Using MSSQL2005, Can I truncate a table with a foreign key constraint if I first truncate the child table(the table with the primary key of the FK relationship)?
I know I can use a DELETE without a where clause and then RESEED the identity OR
Remove the FK, truncate and recreate but I thought as long as you truncate the child table you...
I'm working with a database and I want to start using LINQ To SQL with it. The database doesn't have any FKs inside of it right now for performance reasons. We are inserting millions of rows at a time to the DB which is why there aren't any FKs.
So I'm thinking I'm going to add nonenforced FKs to the database to describe the relationshi...
I have a foreign key constraint between tables Sessions and Users. Specifically, Sessions.UID = Users.ID. Sometimes, I want Sessions.UID to be null. Can this be allowed? Any time I try to do this, I get an FK Constraint Violation.
Specifically, I'm inserting a row into Sessions via LINQ. I set the Session.User = null; and I get this err...
I'm evaluating using EF against an existing schema - the problem is that I can't work out how to set up associations between tables where the foreign key is NOT the primary key of the master table.
As an example, a "foo" may have many "bars" is defined like this (forgive the pseudocode)
table foo {
int foo_id pk,
char(10) foo_code...
I have a situation which (simplified) looks like this:
Table UNITS has a PK on UNITS.NAME. (unit name, varchar(12))
Table DEPTS has a PK on DEPTS.NAME. (dept name, varchar(12))
I want to create a table with column UNIT_NAME_OR_DEPT_NAME, with the
requirement that data in this column must be either a valid unit
name or a valid departmen...
What and when is the best way to use FK's without geting FK "redundancy".
Let's say that i have three tables Account, Category and Product.
1: Table Account
Definition:
Id, Primary BigInt
Name, Varchar
2: Table Category
Definition:
Id, Primary BigInt
AccountId, BigInt ForeignKey
Name, Varchar
3: Table Product
Definition:
...
I want to join 2 tables using entity framework. I want the join to the second table to be on a non-primary key column.
e.g. I have a table Foo with fields
Foo.Id (PK)
Foo.DbValue
and table Bar
Bar.Id (PK)
Bar.DbValue
Bar.Description
And I want to join Foo to Bar in EF on the DbValue field.
In hibernate/nhibernate one can do this...
I have a situation where I have a table that has a soft foreign key to link records in the table to one of many other tables depending on another value in the table. To demonstrate:
TableOfTables: Id, TableName
HistoryTable: Id, TableOfTableId, NumberedTableId, etc...
Table1: Id, etc...
Table2: Id, etc...
Table3: Id, etc...
TableOf...