名称 类型 可否为空 备注
考勤编号 整型 否
员工编号 整型 否
到达时间 日期型 可
记录者编号 整型 可 不可与员工编号相同
考勤类型 字符串 长度 4 否 可取值 “缺勤”、“迟到”、“早退”
请求重新审核 整型 可
日期 日期型 否
主键:员工考勤表的主键是考勤编号字段,类型为整型,设置自动增量。
外键:员工考勤表的外键是员工编号和记录者编号,其中员工编号类型为整型,用于与员工表中的员工编号字段关联;记录者编号类型为整型,用于与员工表中的员工编号字段关联。 约束:员工考勤表中的记录者编号不可与员工编号相同;员工考勤表中的考勤类型字段只能取“缺勤”、“迟到”、“早退”。
索引:主键字段考勤编号具有自动创建的聚集索引。
在SQL上运行一直出现错误
8 个解决方案
#1
数据库中同一张表中的两个字段外键连接到另一张表的同一个字段 ?????这样也行???
#2
应该没有问题.是你表中已有数据不符合要求,先检查后再创建约束.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[员工表](
[员工编号] [int] NOT NULL,
[姓名] [varchar](10) NULL,
CONSTRAINT [PK_tb1] PRIMARY KEY CLUSTERED
(
[员工编号] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[考勤表](
[编号] [int] NOT NULL,
[考勤日期] [varchar](10) NULL,
[被考勤人] [int] NOT NULL,
[考勤人] [int] NOT NULL,
CONSTRAINT [PK_tb2] PRIMARY KEY CLUSTERED
(
[编号] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[考勤表] WITH CHECK ADD CONSTRAINT [FK_tb2_tb1] FOREIGN KEY([被考勤人])
REFERENCES [dbo].[员工表] ([员工编号])
GO
ALTER TABLE [dbo].[考勤表] CHECK CONSTRAINT [FK_tb2_tb1]
GO
ALTER TABLE [dbo].[考勤表] WITH CHECK ADD CONSTRAINT [FK_tb2_tb11] FOREIGN KEY([考勤人])
REFERENCES [dbo].[员工表] ([员工编号])
GO
ALTER TABLE [dbo].[考勤表] CHECK CONSTRAINT [FK_tb2_tb11]
GO
ALTER TABLE [dbo].[考勤表] WITH CHECK ADD CONSTRAINT [CK_考勤表] CHECK (([被考勤人]<>[考勤人]))
GO
ALTER TABLE [dbo].[考勤表] CHECK CONSTRAINT [CK_考勤表]
#3
帮顶
#4
关注
#5
多谢指点,问题已解决
#6
怎么做到的。我想知道,我遇到问题了。
#7
我也遇到问题了,说
解决方法啊
解决方法啊
#8
这个也许有帮助http://topic.csdn.net/t/20061212/09/5223728.html
#1
数据库中同一张表中的两个字段外键连接到另一张表的同一个字段 ?????这样也行???
#2
应该没有问题.是你表中已有数据不符合要求,先检查后再创建约束.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[员工表](
[员工编号] [int] NOT NULL,
[姓名] [varchar](10) NULL,
CONSTRAINT [PK_tb1] PRIMARY KEY CLUSTERED
(
[员工编号] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[考勤表](
[编号] [int] NOT NULL,
[考勤日期] [varchar](10) NULL,
[被考勤人] [int] NOT NULL,
[考勤人] [int] NOT NULL,
CONSTRAINT [PK_tb2] PRIMARY KEY CLUSTERED
(
[编号] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[考勤表] WITH CHECK ADD CONSTRAINT [FK_tb2_tb1] FOREIGN KEY([被考勤人])
REFERENCES [dbo].[员工表] ([员工编号])
GO
ALTER TABLE [dbo].[考勤表] CHECK CONSTRAINT [FK_tb2_tb1]
GO
ALTER TABLE [dbo].[考勤表] WITH CHECK ADD CONSTRAINT [FK_tb2_tb11] FOREIGN KEY([考勤人])
REFERENCES [dbo].[员工表] ([员工编号])
GO
ALTER TABLE [dbo].[考勤表] CHECK CONSTRAINT [FK_tb2_tb11]
GO
ALTER TABLE [dbo].[考勤表] WITH CHECK ADD CONSTRAINT [CK_考勤表] CHECK (([被考勤人]<>[考勤人]))
GO
ALTER TABLE [dbo].[考勤表] CHECK CONSTRAINT [CK_考勤表]
#3
帮顶
#4
关注
#5
多谢指点,问题已解决
#6
怎么做到的。我想知道,我遇到问题了。
#7
我也遇到问题了,说
解决方法啊
解决方法啊
#8
这个也许有帮助http://topic.csdn.net/t/20061212/09/5223728.html