View Single Post
  #1 (permalink)  
Old January 7th, 2007, 10:45 AM
AzlanAziz AzlanAziz is offline
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to AzlanAziz
Default insert value into multiple table

i hav 2 tables where the field StudentID is in both table.StudentID is a primary key in table Student and becomes foreign key in table StudentSchedules(StuddentID isn't auto increment). How can i populate both table at the same time?

CREATE TABLE [Student] (
    [StudentID] VARCHAR(40) NOT NULL,
    [Name] VARCHAR(40),
    CONSTRAINT [PK_Student] PRIMARY KEY ([StudentID])
)

CREATE TABLE [StudentSchedules] (
    [ClassID] INTEGER IDENTITY(0,1) NOT NULL,
    [ClassStatus] VARCHAR(40),
    [StudentID] VARCHAR(40) NOT NULL,
    CONSTRAINT [PK_StudentSchedules] PRIMARY KEY ([ClassID], [StudentID])
)

ALTER TABLE [StudentSchedules] ADD CONSTRAINT [Student_StudentSchedules]
    FOREIGN KEY ([StudentID]) REFERENCES [Student] ([StudentID]) ON DELETE CASCADE ON UPDATE CASCADE
Reply With Quote