alter table tablename add columnName int default 0
alter table <表名> add <列名> <默认值类型> default '<默认值>'例如 要在表TEST中添加一列 ABC ,类型是 VARCHAR,默认值是AA 语句:alter table TEST add ABC VARCHAR(2) default 'AA'
alter table <表名> add <列名> <默认值类型> default '<默认值>'
alter table TableName Add Col1 Type Default 'default '
alter table [tb] add [column_name] default '[value]'
--生成測試表 SELECT TOP 10 ID=IDENTITY(INT,1,1) INTO T FROM sysobjectsgo ALTER TABLE T ADD Date DATETIME DEFAULT GETDATE() WITH VALUES; GO SELECT * FROM T --查看 /* ID Date 1 2011-09-27 12:45:02.977 2 2011-09-27 12:45:02.977 3 2011-09-27 12:45:02.977 4 2011-09-27 12:45:02.977 5 2011-09-27 12:45:02.977 6 2011-09-27 12:45:02.977 7 2011-09-27 12:45:02.977 8 2011-09-27 12:45:02.977 9 2011-09-27 12:45:02.977 10 2011-09-27 12:45:02.977 */
alter table tablename add columnName int default 0
设置主键alter table <表名> add constraint <主键名> primary key(<列名>)
设置联合主键alter table <表名> add constraint <主键名> primary key(<列名1>,<列名2>,...,<列名N>)
约束alter table <表名> add constraint <约束名> check (<约束语句>)在输入语句的时候<>是不需要的
语句:alter table TEST add ABC VARCHAR(2) default 'AA'
alter table <表名> add <列名> <默认值类型> default '<默认值>'
alter table TableName Add Col1 Type Default 'default '
SELECT TOP 10 ID=IDENTITY(INT,1,1) INTO T FROM sysobjectsgo
ALTER TABLE T ADD Date DATETIME DEFAULT GETDATE() WITH VALUES;
GO
SELECT * FROM T --查看
/*
ID Date
1 2011-09-27 12:45:02.977
2 2011-09-27 12:45:02.977
3 2011-09-27 12:45:02.977
4 2011-09-27 12:45:02.977
5 2011-09-27 12:45:02.977
6 2011-09-27 12:45:02.977
7 2011-09-27 12:45:02.977
8 2011-09-27 12:45:02.977
9 2011-09-27 12:45:02.977
10 2011-09-27 12:45:02.977
*/
--添加
Alter Table Table_name
Add column_name type(类型) 是否为空 约束
--删除
把Add改成drop就可以了