[英]Can't get this table and constraint right in SQL
I'm doing this exercise and and I can't get it right - can anybody help me this? 我正在做这个练习而且我做不到 - 有人可以帮助我吗?
Write a second script called
2_CreateTables.sql
that will create theDepartment
andEmployees
tables in theFinalExam
database with the following information: 编写第二个名为2_CreateTables.sql
脚本,该脚本将使用以下信息在FinalExam
数据库中创建Department
和Employees
表:
Department
table Information: Department
表信息:
Column Name Data Type Allow Nulls?
--------------------------------------------------------------
DepartmentID Integer No
DepartmentName Variable length character data No
GroupName Variable length character data Yes
ModifiedDate Small date and time No
AutoNumber: 自动编号:
Make the DepartmentID
automatically number starting with 100 and increment by 5. 使DepartmentID
自动从100开始,并以5递增。
Constraints : 制约因素 :
The DepartmentID
column will be defined as a clustered primary key called PK_Department_DepartmentID
. DepartmentID
列将定义为名为PK_Department_DepartmentID
的聚簇主键。
The ModifiedDate
column will have a default constraint called DF_DeptModified
with the system date and time as the default value. ModifiedDate
列将具有名为DF_DeptModified
的默认约束,系统日期和时间为默认值。
This is what I have so far. 这就是我到目前为止所拥有的。
CREATE TABLE Deparment
DeparmentID int not null,
DeparmentName varchar(100) not null,
GroupName varchar(50) null,
ModifiedDate datetime not null,
Assuming you're using SQL Server - try this: 假设您正在使用SQL Server - 试试这个:
CREATE TABLE dbo.Department
(DepartmentID INT IDENTITY(100, 5) NOT NULL,
DepartmentName VARCHAR(100) NOT NULL,
GroupName VARCHAR(50) NULL,
ModifiedDate SMALLDATETIME NOT NULL
CONSTRAINT DF_DeptModified DEFAULT(GETDATE()),
CONSTRAINT PK_Department_DepartmentID
PRIMARY KEY CLUSTERED (DepartmentID)
)
GO
Changes made: 做出的改变:
( )
after your CREATE TABLE (name)
statement 确保在CREATE TABLE (name)
语句之后有开始和结束括号( )
IDENTITY(100, 5)
clause to the DepartmentID
to make it auto-numbering according to the requirements 将IDENTITY(100, 5)
子句添加到DepartmentID
,使其根据要求自动编号 ModifiedDate
to be SMALLDATETIME
as defined in the textual requirements (you had DATETIME
) 将ModifiedDate
的数据类型更改为文本要求中定义的SMALLDATETIME
(您有DATETIME
) Deparment
to Department
固定所有的Deparment
,以Department
ModifiedDate
为ModifiedDate
添加了默认约束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.