常见T-SQL命令 - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
Jul 12

常见T-SQL命令 不指定

tommyhu , 22:06 , ASP.NET , Comments(0) , Trackbacks(0) , Reads(4178) , Via Original Large | Medium | Small

alter table yourtable add constaints ConstaintName primarykey(columnNmae)

or

create table yourtable(column1 int primary key,....)
--增加列
alter table [TableName] add [P_ID] bigint not null default 0
--删除列
alter table [TableName] drop column [P_ID]
--设置主键
alter table [TableName] add constraint PK_TableName primary key (P_ID)
--删除主键
alter table [TableName] drop constraint PK_TableName
--创建聚集索引(一个表中允许一个聚集索引)
CREATE CLUSTERED INDEX [tTopIndex] ON [TableName] ([P_ID]) ON [PRIMARY]
--创建非聚集索引
CREATE INDEX [tTopIndex] ON TableName ([P_ID]) ON [PRIMARY]
--删除索引
drop index [TableName].[tTopIndex]
--增加字段说明
EXECUTE sp_addextendedproperty N'MS_Description', N'照片ID', N'user', N'dbo', N'table', N'TableName', N'column', N'P_ID'

1、添加表说明
语法:EXEC sp_addextendedproperty N'MS_Description', @value=N'字段说明' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'表名'
实例:EXEC sp_addextendedproperty N'MS_Description', @value=N'XML查询' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'XmlQuery'
2、更新表说明
语法:EXEC sp_updateextendedproperty N'MS_Description', @value=N'字段说明',@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'表名'
实例:EXEC sp_updateextendedproperty N'MS_Description', @value=N'XML查询' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'XmlQuery'
3、删除表说明
语法:EXEC sp_dropextendedproperty N'MS_Description',@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'表名'
实例:EXEC sp_dropextendedproperty N'MS_Description', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'XmlQuery'
4、添加表字段说明
语法:EXEC sp_addextendedproperty 'MS_Description', @value=N'字段说明' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'表名', @level2type=N'COLUMN', @level2name=N'字段名'
实例:EXEC sp_addextendedproperty 'MS_Description', @value=N'是否为大额签报(0:否;1:是)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Quota_Report', @level2type=N'COLUMN', @level2name=N'IsMaxReport'
5、更新表字段说明
语法:EXEC sp_updateextendedproperty 'MS_Description',@value=N'字段说明',@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'表名', @level2type=N'COLUMN', @level2name=N'字段名'
实例:EXEC sp_updateextendedproperty 'MS_Description', @value=N'是否为大额签报(0:否;1:是)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Quota_Report', @level2type=N'COLUMN', @level2name=N'IsMaxReport'
6、删除表字段说明
语法:EXEC sp_dropextendedproperty 'MS_Description',@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'表名', @level2type=N'COLUMN', @level2name=N'字段名'
实例:EXEC sp_dropextendedproperty 'MS_Description',@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'XmlQuery', @level2type=N'COLUMN', @level2name=N'Name'

▲返回顶部

Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot