Tagged Questions
2
votes
2answers
56 views
Performance effect of indexing foreign keys
My database is for an HR application with performance reviews and I am interested in whether I should index my foreign key.
There are two tables involved. The first is a ratings table with 2 columns: ...
3
votes
1answer
66 views
Many:Many with Shared Relation
I'm modelling data with multiplicity like this:
Each Composition/Anthology related pair must share a Composer. Also, each Anthology must contain at least one Composition. How would you recommend I ...
2
votes
1answer
47 views
How to enforce a nullable foreign key?
I have a relation between two tables. The foreign key table can have a row related in the primary table. There's a way to enforce the value of the FK column to be NULL or one of the values of the PK ...
1
vote
3answers
50 views
What is the benefit of two FK, when one of them can be deduced from another table?
The third party Microsoft SQL Server database I'm working on is using the structure which can be illustrated with this example:
Let's take three tables:
Shop which is the topmost level and ...
0
votes
1answer
184 views
Foreign Key - One Child Table to Multiple Parent Tables
Maybe I'm thinking of this problem in the wrong way, but we maintain an AccessControl table that is a child to several parent tables (e.g. CompanyItems, SystemFiles, etc.). I'm trying to make sure we ...
0
votes
0answers
72 views
How to represent class table inheritance (current DBMS-specific way please)?
I want to implement class either-or table inheritance (Account, CatAccountDetails, DogAccountDetails) in SQL Server.
I found a recommendation for MySQL here (How do I map an IS-A relationship into a ...
0
votes
1answer
363 views
To drop a table, do I have to drop all foreign key constraints or can I just NOCHECK them?
I know you cannot drop a table that has active foreign key constraints.
So I was wondering is it safe to:
ALTER TABLE myTable NOCHECK CONSTRAINT all
DROP TABLE myTable
Rather than dropping the ...
0
votes
0answers
134 views
Consequences of multiple FK's from same column to multiple tables
I know it's possible to create multiple FK's to different tables using the same column, other than the performance hit caused by having a FK, are there any negative consequences of doing so?
...
4
votes
1answer
179 views
Performance tuning a cascading delete with many foreign keys
I have a delete query that is taking a long time. Looking at the execution plan, I see that most of the estimated cost in the delete query is in a section of the data model that had a lot of data ...
3
votes
1answer
504 views
Generate insert statements for table AND related data
I'm looking to move data from tables and related tables between 2 databases. The trouble is the primary keys are out of sync.
Is anyone aware of a tool which can generate insert statements for a ...
3
votes
1answer
447 views
Why does altering a table and adding a foreign key create an extra constaint?
Edit: It was a default constraint as a result of setting a default value when adding the column. The name gave it away when starting with 'DF__'. Anyway, solved it by adding the column and manually ...
4
votes
2answers
2k views
Primary key vs. unique index: performance difference with foreign keys?
Will there be any difference in performance if you compare a query fetching data via a join between two tables where there's a relationship against either of the following:
A primary key
A unique ...
3
votes
2answers
1k views
Will a delete then insert within a transaction cascade?
I had a question about what the expected and actual behaviour for the following scenario is.
The scenario is one where a database table ([table1]) is cleared and reloaded every day. The table has an ...
1
vote
1answer
339 views
Using a foreign key on multiple fields in one table
Simple question probably.
For two tables. A one to many relation is created from A -> B, TeamID -> Fk_Team, however there are multiple fields that need to reference this one relationship how does ...
0
votes
2answers
133 views
Merging Results while avoiding Key Constraint Error?
I have a table with a primary key which is two integer fields, each a foreign key to a different table. (Multi to Multi table)
In one of the foreign tables two rows are merged and this table is ...
4
votes
1answer
1k views
How do you create a relationship to a non-primary key in SQL Server?
I have a Users table which has two columns a primary key called UserID and another column called UserName.
UserID (int) PK
UserName (varchar(256)
They are both unique but I decided for reasons to ...