触发器 ON Table 将 INSERT 触发到另一个具有 NOT NULL 约束且具有 float 数据类型的 table
Trigger ON Table which fire INSERT into another table which has NOT NULL constraint , which has float datatype
CREATE TRIGGER studenttr ON tstudentlog
AFTER INSERT
AS
BEGIN
INSERT INTO TABLE tstudent(sname, marks)
SELECT sname,marks FROM INSERTED
END
tstudent的结构
CREATE TABLE tstudent
(
name VARCHAR(20),
marks FLOAT NOT NULL
)
ALTER TABLE tstudent ADD DEFAULT (0) FOR marks
当我在将记录插入 tstudentlog 时不传递标记列中的数据时
我得到一个错误:
Cannot insert the value NULL into column 'marks', table 'tstudent'; column does not allow nulls. INSERT fails. The statement has been terminated.
我尝试了以下但没有用
INSERT INTO TABLE tstudent(sname)
SELECT sname
FROM INSERTED
where marks is null;
我想传递 NULL 值给 tstudent table 并且希望这些情况由 'DEFAULT VALUES kept in tstudent'
处理
我怎样才能做到这一点?
我在 table 中的默认值有很多问题,
在 insert 语句上使用 coalesce 会很顺利吗?
CREATE TRIGGER studenttr ON tstudentlog
AFTER INSERT
AS
BEGIN
INSERT INTO TABLE tstudent(sname, marks)
SELECT sname,coalesce(marks,0) FROM INSERTED
END
CREATE TRIGGER studenttr ON tstudentlog
AFTER INSERT
AS
BEGIN
INSERT INTO TABLE tstudent(sname, marks)
SELECT sname,marks FROM INSERTED
END
tstudent的结构
CREATE TABLE tstudent
(
name VARCHAR(20),
marks FLOAT NOT NULL
)
ALTER TABLE tstudent ADD DEFAULT (0) FOR marks
当我在将记录插入 tstudentlog 时不传递标记列中的数据时
我得到一个错误:
Cannot insert the value NULL into column 'marks', table 'tstudent'; column does not allow nulls. INSERT fails. The statement has been terminated.
我尝试了以下但没有用
INSERT INTO TABLE tstudent(sname)
SELECT sname
FROM INSERTED
where marks is null;
我想传递 NULL 值给 tstudent table 并且希望这些情况由 'DEFAULT VALUES kept in tstudent'
处理我怎样才能做到这一点?
我在 table 中的默认值有很多问题, 在 insert 语句上使用 coalesce 会很顺利吗?
CREATE TRIGGER studenttr ON tstudentlog
AFTER INSERT
AS
BEGIN
INSERT INTO TABLE tstudent(sname, marks)
SELECT sname,coalesce(marks,0) FROM INSERTED
END