Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Creating Relationships

Author  Topic 

globemast
Starting Member

32 Posts

Posted - 2003-03-14 : 15:41:39
Hello ...

I am new to creating Relationships between tables but i will briefly explain what i want to do. I have 3 tables in which i have set on all of the as primary key the column "Username". I want when i change information all tables to be updated. when i created the Relationships in the SQL Enteprise Manager i got the following error:

- Unable to create relationship 'FK_Logins_People'.
ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'FK_Logins_People'. The conflict occurred in database 'Intranet', table 'People', column 'Username'.


Can someone please help me....
thank you

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-14 : 15:46:07
A foreign key is not going to update the records unless you have specified the ON UPDATE CASCADE option in the constraint. I am not sure that you are going to be able to do this through Enterprise Manager. Your best bet is to use Query Analyzer. See ALTER TABLE syntax in SQL Server Books Online for the specific syntax.

Btw, if your primary key is Username on your three tables, you might want to reconsider your database design.

Post your DDL for the three tables in this thread and we'll see if we can help you on both aspects.

Tara
Go to Top of Page

globemast
Starting Member

32 Posts

Posted - 2003-03-14 : 16:05:43
What do you mean DDL? I can write you the table names, and attributes of each table if this is what you want?

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-14 : 16:46:19
DDL stands for data definition language. If you could just provide the CREATE statements used to create the tables or if you used Enterprise Manager to do it, just generate the scripts from Enterprise Manager or simply just simply let us know what the table names are and what it's columns are and how they relate, plus what are the column's data types.

Tara
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-03-14 : 16:55:05
My guess is that you have rows in one table that have a Primary key, that doesn't exists in the "Parent" Table.

Table1 (Parent)
key
1
2
3
Table2 (Child)
1
2
3
4
In this case creating the foreign key betweens these 2 tables will fail if you identify table 1 as the Parent.

You can write sql to find the offending rows:

Select l.* From Table2 l Left Join Table1 r On l.key = r.key Where r.key Is Null

BUT, I would really search the site for some background on relational database design.

Such a search might give you:

http://www.sqlteam.com/item.asp?ItemID=122

Good Luck

Brett

8-)
Go to Top of Page
   

- Advertisement -