使用 ALTER TABLE 语句来对已有的表进行:添加、修改或删除列的操作。
添加列:
InBlock.gifALTER TABLE table_name
InBlock.gifADD column_name datatype
例如:
InBlock.gifALTER TABLE Study
InBlock.gifADD s_status bit
为列添加默认值:
1,在添加列时,添加默认值:
InBlock.gifALTER TABLE table_name
InBlock.gifADD column_name datatype
default(value)
例如:
InBlock.gifALTER TABLE Study
InBlock.gifADD s_status bit
default(0)
2,用给列添加约束的方式添加:
InBlock.gifALTER TABLE table_name
InBlock.gifADD CONSTRAINT [DF_name]
default(value) FOR column_name
例如:
InBlock.gifALTER TABLE Study
InBlock.gifADD CONSTRAINT [DF_status]
default(1) FOR s_status
更改列的数据类型:
InBlock.gifALTER TABLE table_name
InBlock.gifALTER COLUMN column_name datatype
例如:
InBlock.gifALTER TABLE Study
InBlock.gifALTER COLUMN s_status nchar(16)
删除列:
InBlock.gifALTER TABLE table_name
InBlock.gifDROP COLUMN column_name
例如:
InBlock.gifALTER TABLE Study
InBlock.gifDROP COLUMN s_status