當前位置:首頁 » 編程語言 » sql報錯213
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql報錯213

發布時間: 2023-08-04 02:23:44

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