-
Table Keys
How does one link the table keys so that data used to update one table will update the other table? In other words how to get data to pass from ont table to the linked table. Thanks
-
if it is sql server.....
cascading update and delete can be done with referential integity.
cascading insert can be done by insert trigger.
-
Table Keys
MAK thanks for your reply but Triggers at this point are WAY beyond us. Could you please make it a very simplified answer? Thank you so much.
-
--Follow step by step
--step1 Create parent table
Create table Department (Deptid int constraint PK_Department primary key,
DepartmentName varchar(100))
insert into Department select
--step2 insert values
1,'Finance'
insert into Department select 2,'Marketing'
--step3 Create child table
Create table Employee (empid int constraint PK_Employee primary key,
Fname varchar(50), Lname varchar(50), Deptid int constraint FK_Department references
DepartMent(deptid) on delete cascade on Update cascade )
--step4 insert values
insert into Employee select 1,'Sam','rooban',1
insert into Employee select 2,'Amar','Kumar',NULL
insert into Employee select 3,'Kumar','Sanu',2
--step5 Update parent table
update department set deptid=5 where deptid=2
--step 6. see the change
select * from employee
--step 7. Delete a row in the parent table
delete department where deptid=5
--step 6. see the change
select * from employee
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|