1、student
CREATE TABLE [dbo].[student](
[SId] [nchar](10) NULL,
[Student] [nchar](10) NULL,
[Mark] [float] NULL
)
2、course
CREATE TABLE [dbo].[course](
[CId] [nchar](10) NULL,
[Student] [nchar](10) NULL,
[Course] [nchar](10) NULL,
[Mark] [float] NULL
)
我想对student表创建insert 触发器,当有数据插入student表时,
把其中的Student,Mark 两个值插入到course表对应的字段中,
不知道能否实现呢?
请大家给个帮助,谢谢
6 个解决方案
#1
可以实现。
#2
具体的触发器代码该怎么写呢?
#3
create trigger tri_student on student
for insert
as
begin
if (select count(1) from student)=0
then
print '未插入数据'
else
insert into course(Student,Mark )select Student,Mark from inserted
end
#4
问题解决了么?????
#5
楼主,只插两个值,那Cid和Course让它空着?
F姐姐的代码很蛋疼,语法不对,那句打印也是多余的
F姐姐的代码很蛋疼,语法不对,那句打印也是多余的
#6
3楼思路完全正确
create trigger tri_student on student
for insert
as
begin
insert into course(Student,Mark)
select Student,Mark from inserted
end
create trigger tri_student on student
for insert
as
begin
insert into course(Student,Mark)
select Student,Mark from inserted
end
#1
可以实现。
#2
具体的触发器代码该怎么写呢?
#3
create trigger tri_student on student
for insert
as
begin
if (select count(1) from student)=0
then
print '未插入数据'
else
insert into course(Student,Mark )select Student,Mark from inserted
end
#4
问题解决了么?????
#5
楼主,只插两个值,那Cid和Course让它空着?
F姐姐的代码很蛋疼,语法不对,那句打印也是多余的
F姐姐的代码很蛋疼,语法不对,那句打印也是多余的
#6
3楼思路完全正确
create trigger tri_student on student
for insert
as
begin
insert into course(Student,Mark)
select Student,Mark from inserted
end
create trigger tri_student on student
for insert
as
begin
insert into course(Student,Mark)
select Student,Mark from inserted
end