您的位置:首页 > 数据库

SQl语句修改和查看数据表的基本语句

2014-11-30 15:49 399 查看
--添加字段
alter table GSP_MHJ alter add Salequantity money 
--删除字段
ALTER TABLE Files DROP COLUMN imgFile  
--修改字段属性
alter table GSP_MHJ alter column Salequantity money
alter table GSP_MHJ alter column Salequantity money not null;
--修改字段名:
alter table tab_info rename column createname to thisname;
--修改默认值
alter table tabinfo add constraint df default('嘿嘿') for thisname;
--添加说明
EXECUTE sp_addextendedproperty N'MS_Description', '描述内容', N'user', N'dbo', N'table', N'表名', NULL, NULL
EXECUTE sp_addextendedproperty  N'MS_Description', '描述内容', N'user', N'dbo', N'table', N'Products', N'column', N'列名'
--修改说明
EXECUTE sp_updateextendedproperty N'MS_Description', '描述内容', N'user', N'dbo', N'table', N'表名', NULL, NULL
EXECUTE sp_updateextendedproperty  N'MS_Description', '描述内容', N'user', N'dbo', N'table', N'Products', N'column', N'列名'
--获取表中所有字段的说明,并且<>'' --g.[value]<>''
SELECT a.name FiledName,g.[value] AS Notes
FROM syscolumns a left join systypes b on a.xtype=b.xusertype inner join sysobjects d
on a.id=d.id and d.xtype='U' and d.name<>'dtproperties' left join sys.extended_properties g
on a.id=g.major_id AND a.colid = g.minor_id WHERE d.[name] ='表名' and g.[value]<>'' order by a.id,a.colorder<pre name="code" class="sql">
--创建唯一性约束
alter table UnitTypes  add constraint OrderID_only unique (OrderID)
alter table 表名 add constraint 约束名 unique (列名[也可称为字段])


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: