我有两张桌子,一张是
peson contains(personid Identity, firstname,Lastname,PlaceOfBirth,Gender)
和另一个
Education contains (Eduid identity, egreename,boardUniver,yearOfPassing,obtainedMarks, personid)
现在我的问题是每个人都有超过 1 度,但有些人有 1 或 2 度,那么我该如何跳过插入查询?
第一个表
Create table person(personid int Identity(1,1) primary key, firstname nvarchar(40), Lastname nvarchar(40), PlaceOfBirth nvarchar(40), Gender nvarchar(10))
第二张表
create table Education(Eduid int identity(1,1) primary key, Degreename nvarchar(40), boardUniver nvarchar(40), yearOfPassing nvarchar(40), obtainedMarks numeric(10,2), personid int,
constraint fk_eduPerson foreign key (personid) references person(personid))
存储信息的过程
Create procedure EmpDetails
(
@Firstname nvarchar(40), @Lastname nvarchar(40), @PlaceOfBirth nvarchar(40), @Gender nvarchar(8),
@Degreename0 int, @boardUniver0 nvarchar(40), @yearOfPassing0 nvarchar(20), @obtainedMarks0 int,
@Degreename1 int, @boardUniver1 nvarchar(40), @yearOfPassing1 nvarchar(20), @obtainedMarks1 int,
@Degreename2 int, @boardUniver2 nvarchar(40), @yearOfPassing2 nvarchar(20), @obtainedMarks2 int,
)
AS BEGIN
declare @personid int
INSERT INTO person(firstname,Lastname,PlaceOfBirth,Gender) values(@firstname,@Lastname,@PlaceOfBirth,@Gender)
SELECT @personid=@@IDENTITY
if(@Degreename0 !=NULL)
BEGIN
INSERT INTO Education(Degreename,boardUniver,yearOfPassing,obtainedMarks, personid) values (@Degreename0,@boardUniver0,@yearOfPassing0,@obtainedMarks0, @personid)
END
IF(@Degreename1 !=null)
BEGIN
INSERT INTO Education(Degreename,boardUniver,yearOfPassing,obtainedMarks, personid) values (@Degreename1,@boardUniver1,@yearOfPassing1,@obtainedMarks1, @personid)
END
IF(@Degreename2!=null)
BEGIN
INSERT INTO Education(Degreename,boardUniver,yearOfPassing,obtainedMarks, personid) values (@Degreename2,@boardUniver2,@yearOfPassing2,@obtainedMarks2,@personid)
END
END
这不起作用..这会将所有行插入空..还有其他解决方案吗?如果有其他建议请给我..谢谢