更新时间:2021-09-16 04:34:30
您遇到三个问题:
;
终止语句。 FOR MEMBER_ID
,可能应该是 FOR Sys_date
。 ADD
,但不要。;
at the end of your second line of code.FOR MEMBER_ID
in the last statement, which should probably be FOR Sys_date
.ADD
but don't have to.假定此表结构为:
CREATE TABLE Member (MEMBER_ID BIGINT NOT NULL, Sys_date DATETIME);
此DDL将起作用:
ALTER TABLE MEMBER
ADD CONSTRAINT U_MEMBERID UNIQUE(MEMBER_ID), primary key (MEMBER_ID),
CONSTRAINT Sys_date DEFAULT GETDATE() FOR Sys_date;
请参见此sqlfiddle 。
您可以理论上也可以在 ALTER TABLE
上的MSDN页面,尽管我会很容易地承认那些规格可能很难阅读。以下是他们对其解释的一种刺探:
You can theoretically also see this on the MSDN's page on ALTER TABLE
, though I'd readily admit those specs can be hard to read. Here's a stab at how they explain it:
ALTER TABLE [ database_name . [ schema_name ] . | schema_name . ] table_name
{
ALTER COLUMN column_name
-- Omitted....
| ADD
{
<column_definition>
| <computed_column_definition>
| <table_constraint>
| <column_set_definition>
} [ ,...n ]
-- Omitted....
ADD
关键字出现一次,并且} [,... n]
位告诉您可以在{括号} n
次之间重复位,并用,
隔开。
The ADD
keyword occurs once, and the } [ ,...n ]
bit tells you that you can repeat the bit between {brackets} n
times, separated by a ,
.