日期:2014-05-18  浏览次数:20602 次

建表语句问题
CREATE TABLE DEPARTMENTS (  
[DeptID] [int] NOT NULL, --部门ID
[DeptName] [varchar](20) NOT NULL , --部门名称
[supdeptid] [int] NOT NULL CONSTRAINT ----上级部门的ID 
[sdf] DEFAULT ((1)),
PRIMARY KEY CLUSTERED 
(
[DeptID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


以上见表语句,提示:第 9 行: '(' 附近有语法错误。

请问哪里出错误了?
还有这个PRIMARY KEY CLUSTERED 
(
[DeptID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

可不可以对一个已经存在的表进行修改?
如果可以 该怎么写?

------解决方案--------------------
< column_constraint > ::= [ CONSTRAINT constraint_name ]
{ [ NULL | NOT NULL ]
| [ { PRIMARY KEY | UNIQUE }
[ CLUSTERED | NONCLUSTERED ]
[ WITH FILLFACTOR = fillfactor ]
[ON {filegroup | DEFAULT} ] ]

| [ [ FOREIGN KEY ]
REFERENCES ref_table [ ( ref_column ) ]
[ ON DELETE { CASCADE | NO ACTION } ]
[ ON UPDATE { CASCADE | NO ACTION } ]
[ NOT FOR REPLICATION ]

| CHECK [ NOT FOR REPLICATION ]
( logical_expression ) 


< table_constraint > ::= [ CONSTRAINT constraint_name ]
{ [ { PRIMARY KEY | UNIQUE }
[ CLUSTERED | NONCLUSTERED ]
{ ( column [ ASC | DESC ] [ ,...n ] ) }
[ WITH FILLFACTOR = fillfactor ]
[ ON { filegroup | DEFAULT } ]

| FOREIGN KEY
[ ( column [ ,...n ] ) ]
REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]
[ ON DELETE { CASCADE | NO ACTION } ]
[ ON UPDATE { CASCADE | NO ACTION } ]
[ NOT FOR REPLICATION ]
| CHECK [ NOT FOR REPLICATION ]
( search_conditions ) 



你是SQL么?

对表修改是修改什么
 ALTER TABLE?
------解决方案--------------------
建表语句没有错啊,我这边复制过来就可以用。

------解决方案--------------------
直接在SQL中创建,不用命令。
------解决方案--------------------
CREATE TABLE DEPARTMENTS (
[DeptID] [int] NOT NULL, --部门ID
[DeptName] [varchar](20) NOT NULL , --部门名称
[supdeptid] [int] NOT NULL CONSTRAINT ----上级部门的ID
[sdf] DEFAULT ((1)),
PRIMARY KEY CLUSTERED
(
[DeptID] ASC
) ) ON [PRIMARY]

语句修改按以上就可以了,
语法你自己查帮助 F1, CREATE TABLE 是建表的,ALTER TABLE 是修改表的,
------解决方案--------------------
探讨
CREATE TABLE [dbo].[checkinout](
[id] [int] IDENTITY(1,1) NOT NULL,
[userid] [int] NOT NULL, --员工ID
[checktime] [datetime] NOT NULL, --时间
[checktype] [varchar](1) NOT NULL --签到类型
[verifycode] [……

------解决方案--------------------
SQL code

CREATE TABLE [dbo].[checkinout](
[id] [int] IDENTITY(1,1) NOT NULL, 
[userid] [int] NOT NULL, --员工ID
[checktime] [datetime] NOT NULL, --时间
[checktype] [varchar](1) NOT NULL --签到类型  /*最后少一个逗号*/ 
[verifycode] [int] NOT NULL CONSTRAINT [vcedf] --比对方式 0指纹 1密码 2卡 /*建立约束,不知道你需要建立的约束是什么?*/
[SN] [varchar](20) NULL, --设备序列号
[sensorid] [varchar](5) NULL, 
[WorkCode] [varchar](20) NULL, --工作代码
[Reserved] [varchar](20) NULL,
PRIMARY KEY CLUSTERED  
(
[id] ASC
)[color=#FF0000]WITH (IGNORE_DUP_KEY = OFF)[/color] ON [PRIMARY],  /*还是如同上个问题,将红字一段去掉即可*/
UNIQUE NONCLUSTERED  
(
[userid] ASC,
[checktime] ASC
)[color=#FF0000]WITH (IGNORE_DUP_KEY = OFF)[/color] ON [PRIMARY]   /*同上*/
) ON [PRIMARY]