SQLServer数据库实用技术(46)
时间:2007-12-23 来源:不详 作者:迈克DB
当表创建好后,可能根据需要要对表的列、约束等属性进行添加、删除或修改,这就需要修改表结构。
7.4.1 用Enterprise Manager 修改
在Enterprise Manager 中选择要进行改动的表,单击右键,从快捷菜单中选择“DesignTable”选项,则会出现如图7-4 所示的修改表结构对话框。可以在图7-4 所示的对话框中修改列的数据类型、名称等属性或添加、删除列,也可以指定表的主要害字约束。单击工具栏中的图标,出现如图7-5 所示的编辑表和约束的属性的对话框。可以在其中编辑各种约束和一些表的属性。 内容来自dedecms
7.4.2 用ALTER TABLE 命令修改
ALTER TABLE 命令可以添加或删除表的列、约束,也可以禁用或启用已存在的约束
或触发器。其语法如下:
ALTER TABLE table
{ [ALTER COLUMN column_name
{ new_data_type [ (precision[, scale] ) ]
[ COLLATE < collation_name > ]
[ NULL | NOT NULL ]
| {ADD | DROP} ROWGUIDCOL } ]
| ADD
{ [
| column_name AS computed_column_expression
}[,...n]
| [WITH CHECK | WITH NOCHECK] ADD
{ }[,...n]
| DROP
{ [CONSTRAINT] constraint_name
| COLUMN column
}[,...n]
| {CHECK | NOCHECK} CONSTRAINT
{ALL | constraint_name[,...n]}
| {ENABLE | DISABLE} TRIGGER
{ALL | trigger_name[,...n]}
织梦好,好织梦
}
[ [ DEFAULT constant_expression ]
| [ IDENTITY [(seed, increment ) [NOT FOR REPLICATION] ] ]
]
[ ROWGUIDCOL ]
[ COLLATE < collation_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)}
::= [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])]
[NOT FOR REPLICATION]
[ ON DELETE { CASCADE | NO ACTION } ]
[ ON UPDATE { CASCADE | NO ACTION } ]
| CHECK [NOT FOR REPLICATION]
(search_conditions)}
各参数说明如下:
文章评论
共有位Admini5网友发表了评论 查看完整内容