--创建学生介绍自己(IntroduceYourself)表
CREATE TABLE IntroduceYourself(
cStudentsId char(10) NOT NULL,
vSelfAssessment varchar(100) NOT NULL,
vSelfSpecialty varchar(100) NULL,
vHobbiesInterest varchar(100) NULL
) ALTER TABLE IntroduceYourself
ADD CONSTRAINT fkIntroduceYourself FOREIGN KEY (cStudentsId) REFERENCES Students(cStudentsId)--创建学生教育经历(Education)表
CREATE TABLE Education(
cStudentsId char(10) NOT NULL,
vEducationUndergo varchar(100) NOT NULL,
vTrainUndergo varchar(100) NULL

ALTER TABLE Education
ADD CONSTRAINT fkEducation FOREIGN KEY (cStudentsId) REFERENCES Students(cStudentsId)--创建学生求职信息(ApplyJobInformation)表
CREATE TABLE ApplyJobInformation(
vExpectWorkPlace varchar(30) NULL,
vIndustry varchar(70) NOT NULL,
cPosition char(50) NOT NULL,
dApplyTime datetime NOT NULL,
cStudentsId char(10) NOT NULL
)ALTER TABLE ApplyJobInformation
ADD CONSTRAINT fkApplyJobInformation FOREIGN KEY (cStudentsId) REFERENCES Students(cStudentsId)
alter table dbo.ApplyJobInformation add msalary money null
我想在删除学生求职信息(ApplyJobInformation)表中一条cStudentsId = 2010121015的一行记录数据,
同时也要删除学生教育经历(Education)表中一条cStudentsId = 2010121015的一行记录数据,
并且还要删除学生介绍自己(IntroduceYourself)表中一条cStudentsId = 2010121015的一行记录数据
该怎么做到呢,希望各位高手指点一二,不尽感激

解决方案 »

  1.   

    用级联删除就行了,在外健上加这选项on delete cascade
    CREATE TABLE IntroduceYourself(
    cStudentsId  char(10)  NOT NULL,
    vSelfAssessment  varchar(100) NOT NULL,
    vSelfSpecialty  varchar(100) NULL,
    vHobbiesInterest varchar(100) NULL
    )  ALTER TABLE IntroduceYourself
    ADD CONSTRAINT fkIntroduceYourself FOREIGN KEY (cStudentsId) REFERENCES Students(cStudentsId)--创建学生教育经历(Education)表
    CREATE TABLE Education(
    cStudentsId  char(10)  NOT NULL,
    vEducationUndergo varchar(100) NOT NULL,
    vTrainUndergo  varchar(100) NULL
    )  
    ALTER TABLE Education
    ADD CONSTRAINT fkEducation FOREIGN KEY (cStudentsId) REFERENCES Students(cStudentsId) on delete cascade--创建学生求职信息(ApplyJobInformation)表
    CREATE TABLE ApplyJobInformation(
    vExpectWorkPlace varchar(30)  NULL,
    vIndustry  varchar(70)  NOT NULL,
    cPosition  char(50)  NOT NULL,
    dApplyTime  datetime  NOT NULL,
    cStudentsId  char(10)  NOT NULL
    )
    ALTER TABLE ApplyJobInformation
    ADD CONSTRAINT fkApplyJobInformation FOREIGN KEY (cStudentsId) REFERENCES Students(cStudentsId) on delete cascade
      

  2.   

    本帖最后由 roy_88 于 2011-11-11 21:09:20 编辑