Results 1 to 4 of 4

Thread: Table Keys

  1. #1
    Join Date
    Apr 2004
    Posts
    21

    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

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    if it is sql server.....

    cascading update and delete can be done with referential integity.

    cascading insert can be done by insert trigger.

  3. #3
    Join Date
    Apr 2004
    Posts
    21

    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.

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    --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
  •