Updatable views - SQL Server 2008 - sql-server-2008

A question about updatable db views: I'm reading through some MSDN documentation on the subject, and I come across the following restriction:
Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.
I just want to be sure I understand the restriction. I'd like to use views in a couple of my media review projects. The relational data is spread throughout tables, but a view seems to be the best way to be able to consolidate the data I need from multiple tables (some of which are linked via foreign keys) into a centralized location. Since the columns would come from a variety of tables, does this mean I can't run one blanket INSERT or UPDATE to persist changes in all the columns?

You can use an INSTEAD OF trigger on a view to keep your application only dealing with the view instead of the collection of base tables the view references.
Here is an example : Designing INSTEAD OF Triggers

Yes that's what it means. I see no advantage to updating through a view since you have to know what the base tables involved are anyway.

Related

Same table in multple schemas

New to this, I am creating a database for an application. As the schema is becoming visually complex very rapidly, is it possible/feasable/recommended to have the same user_table in multiple schema?
For example, the blogging schema would have the user_table and the rest of the tables related to this activity. The shopping schema would again have the same user_table and the tables to manage the shopping activity. And so forth....
The objective would be to separata the plenty of tables in different schemas so to simplify the overall managements.
In another post, someone suggested creating a synonym in one the of schemas, referencing the other schema table. Is it the way to go or am I totally misrepresenting problem and solution?
Thank you for your time reading this.
A user table serves two diffent features, each in its own schema:
Sharing tables between schemas is not directly possible. There's a feature called federated tables, which however is not enabled by default and must be enabled at compile time of a MySQL server. So, it's rather not available for your task.
Instead you have only two options:
Use a single schema to avoid data duplication.
Use multiple schemas and maintain tables like the user table in each of them in parallel (by executing the same update queries on each of them).

Mini-world as table in a relational database?

In relational databases, if we want to create a database for a football tournament for example, we consider the tournament as the mini-world (the unit for which we want to create a database and collect data). Therefore, we may create tables such as matches, teams, and so on. And, we don't create a table called tournament since we have only THE TOURNAMENT for which we are doing all this.
In practice, that's what I used to do. But, what if I want to save in my database some attributes about the tournament, such as its name, the date and the country in which it takes place... What can I do? Is it a good practice to create a table tournament that has only one record? And if yes, what about foreign keys? Is it good in this case to add the ID of the tournament as a foreign key in the tables matches, teams...? If not, what can be the best practice?
Why I want to store the tournament information in the database? Because I want to create a webpage that reads only dynamic data. I don't want to add those information (tournament name, date...) as static data on the web page.
I am also thinking about the benefit from the possibility of future evolution of the product. Later on, I may have more than one tournament and having the tournament table part of the database will allow a smooth integration of more tournaments without modification of the metadata.
Yes, it is typical to use a row to store relevant single values. (Frequently this is done for parameter settings). But you don't need an id in this row for the tournament or foreign keys to it in other tables until you have multiple tournaments.
Yes, this helps extend to multiple tournaments. It also helps in extending to a "temporal"/historical version of the database where we timestamp each row by when it held so that we can query about the state that was current at a given time. (This typically involves further normalization to have separate tables for columns that change together but possibly at different times from other column sets.)
In moving to multiple tournaments, as with any schema change, it is helpful to redefine the names of old tables as views of new tables. Unfortunately updates through views are typically poorly supported by SQL DBMSs so in that respect it can be useful to have a multiple-tournament-capable design right from the beginning.

MySQL database merge of two databases

I set up two Wordpress blogs a while ago, both obviously having different databases. I've more recently merged these databases into one by changing the tables prefixes, therefore these two 'entities' have the same amount of tables and the same names (as they originate from a Wordpress install) but with different prefixes, i.e.:
Blog1_tabledata1
Blog1_tabledata2
Blog1_tabledata3
Blog1_tabledata4
Blog2_tabledata1
Blog2_tabledata2
Blog2_tabledata3
Blog2_tabledata4
I have now realised that I need to merge these two databases (where they're both using the same tables) so that they can be used in the same Wordpress instance (later separated by tags etc).
What would be the most simple way of doing this?
(Please note I am asking this from a MySQL standpoint - this is not a Wordpress question!)
If you absolutely are not looking for a wordpress solution, that means you are not looking at all domains. By this, I mean that you are not looking at what the data means. This could be a problem. but nevertheless:
figure out the foreign keys. If the tables are MyIsam instead of InnoDB, they will be implicit. Figure out what ID points to what field.
select from one DB and insert into the other. This mean you add the rows of one table to the equivalent of the target database. Auto-increment rows will be fine. But for foreign key (explicit AND implicit) fields here is were the trouble starts.
If you insert, say a user, the user gets a new ID -> You have to find the equivalent of the userid in the old db so you can insert the foreign keys with the right ID. this is tricky and without making this a wordpress-question there is no more help we can give you: just figure out what rows they should be :). it is database // domain specific. (with that I mean you can't just figure that out by looking at the fields, you must know some of what they mean)
If the db is correct, this should work, but I'm not sure if you get into trouble with duplicates (all should go on ID, and you fixed that in step 3 with unique and connected id's. but if your domain doesn't want two accounts, two pages or two whatevers (tags?) to have the same name, you still have a problem. But again, this is domain specific logic and you're specifically asking not to go there.

Using same type for LINQ-to-SQL mapping on different tables

I have a LINQ-to-SQL data context in which two tables exist with different names but identical structures. One table (called CallRecords) holds live/current data, and the other (CallRecordsArchive) holds older records - but with the same field names as the live one.
With the basic mapping LINQ to SQL creates two classes CallRecord and CallRecordsArchive - but since they are the same I'd like to avoid this if possible? That way I don't have to write two queries for each instance?
I did consider creating a JOIN view but with millions of rows in both tables it would be a performance nightmare.
The way I've dealt with this is to create an interface for the common aspects of both tables and have both of the generated classes from your data context implement that interface through the use of the a partial class definition. This way when you want to deal with the type as a single concept you can always refer to it as the interface.
try to use inherit for this issue
check this link for more details.
one more
I hope it is help you.

Creating an AssociationSetMapping for MySQL with the Entity Framework Designer?

I am trying to build an Entity Framework model for my database schema using EF4 and Visual Studio 2010. Since I am stuck using MySQL as our database (for now), I pretty quickly discovered that since MYISAM tables don't support foreign key constraints, the designer does not have any way to automatically create all the associations for you. It is easy enough to go through the model and build them all manually, but I ran into a problem trying to map a pure join table.
Normally if you are using SQL Server or some other database that supports Foreign Keys, the designer will create all the mappings for you and in the case of pure join tables will create an AssociationSetMapping such that the join table is entirely hidden in the model. Instead you end up with a Many to Many mapping between two two primary entities.
However I am at a loss as to how to create this kind of mapping manually? If I create a Many to Many association between my two entities, I end up with a regular Association, not an AssociationSetMapping. There does not appear to be a way to create one of these in the designer than I can figure out, and to tell it which join table is supposed to be used at the database level.
Am I missing something, and there is a way to do this?
If not, I suppose I have to hack the XML directly, but at this point it is not clear what I need to add to the XML files and where, in order to manually create the association set mapping?
Ok, I can answer this one myself. Once you create a many to many association with the designer, you DON'T set a referential constraint on it, but rather use the Mapping Details window to tell the association what table is the join table, and which keys map to which fields in the database. Simple enough once I figured it out :) But I could not find any good documentation on this.