SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
-- 创建 EmployeeInfo 表 CREATE TABLE [dbo].[EmployeeInfo] ( [EmployeeID] int IDENTITY(1,1) NOT NULL, [Name] nvarchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL, [IdentityCard] nvarchar(20) COLLATE Chinese_PRC_CI_AS NOT NULL, [Gender] nvarchar(10) COLLATE Chinese_PRC_CI_AS NULL, [PhoneNumber] nvarchar(15) COLLATE Chinese_PRC_CI_AS NULL, PRIMARY KEY CLUSTERED ([EmployeeID]) ); -- 创建 Attendance 表,并定义外键 CREATE TABLE [dbo].[Attendance] ( [AttendanceID] int IDENTITY(1,1) NOT NULL, [EmployeeID] int NOT NULL, [AttendanceDate] date NOT NULL, [Status] nvarchar(20) COLLATE Chinese_PRC_CI_AS NOT NULL, [Reason] nvarchar(255) COLLATE Chinese_PRC_CI_AS NULL, PRIMARY KEY CLUSTERED ([AttendanceID]), CONSTRAINT [FK_Attendance_EmployeeInfo] FOREIGN KEY ([EmployeeID]) REFERENCES [dbo].[EmployeeInfo] ([EmployeeID]) ON DELETE NO ACTION ON UPDATE NO ACTION ); -- 为 Department 表添加外键约束 ALTER TABLE [dbo].[Department] ADD CONSTRAINT [FK_Department_ManagerEmployeeInfo] FOREIGN KEY ([ManagerEmployeeID]) REFERENCES [dbo].[EmployeeInfo] ([EmployeeID]) ON DELETE NO ACTION ON UPDATE NO ACTION;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear