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)
 change primary key

Author  Topic 

mike009
Starting Member

15 Posts

Posted - 2006-03-18 : 00:40:23
hi
if i have table employee with employee_id as a primary key
how can i assign the primary key to the columns firstname and lastname?

table structure is something like this :

employee_id int not null, firstname varchar(20) not null, lastname varchar(20) not null
the problem is that there is a foreign key in other table that referes to the table employee , so when i try to delete the primary key i get error said i can't delete coze it refers to other table ...

other q
if i create foreign key by this way
alter table le_order
add constraint fk_salesman foreign key (Salesman_id) REFERENCES employee
how can i update this statement and add
on delete set null
and to set it to null is that correct for first problem

thx
note : sorry my english isn't good , if you please excuse me.

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-03-18 : 01:42:11
you can delete the record from the primary table,when its the secondary table data..

The best thing is to write a small trigger on the primary table, either to delete the record from the secondary table or to set them to null..

you can also you the option of Cascade delete.

Just look in Book Online for ON DELETE CASCADE

Hope this helps..

Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page
   

- Advertisement -