1. 求SQL触发器语句
USE [Test]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[部门信息](
[部门编号] [nchar](3) COLLATE Chinese_PRC_CI_AS NOT NULL,
[部门名称] [nchar](10) COLLATE Chinese_PRC_CI_AS NOT NULL,
[员工人数] [int] NOT NULL,
CONSTRAINT [PK_部门信息] PRIMARY KEY CLUSTERED
(
[部门编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
USE [Test]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[员工信息](
[员工编号] [nchar](4) COLLATE Chinese_PRC_CI_AS NOT NULL,
[员工姓名] [nchar](10) COLLATE Chinese_PRC_CI_AS NOT NULL,
[性别] [nchar](2) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF_员工信息_性别] DEFAULT (N'男'),
[出生年月] [datetime] NULL,
[入职时间] [datetime] NULL,
[部门编号] [nchar](3) COLLATE Chinese_PRC_CI_AS NOT NULL,
CONSTRAINT [PK_员工信息] PRIMARY KEY CLUSTERED
(
[员工编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
USE [Test]
GO
ALTER TABLE [dbo].[员工信息] WITH CHECK ADD CONSTRAINT [FK_员工信息_部门信息] FOREIGN KEY([部门编号])
REFERENCES [dbo].[部门信息] ([部门编号]
USE [Test]
ALTER TABLE [员工信息]
ADD CONSTRAINT CK_Employee_Sex CHECK (性别='男' or 性别='女' );
消息213,级别16,状态1,第3 行
插入错误: 列名或所提供值的数目与表定义不匹配
use Test
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER TRIGGER [uEmployee]
ON [dbo].[员工信息] AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
UPDATE [员工信息]
SET 入职时间=getdate()
end
use Test
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER TRIGGER [uEmployee]
ON [dbo].[员工信息] AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
UPDATE [员工信息]
SET 入职时间=getdate()
end