exec sp_help Reports
exec sp_rename 'Reports','Reports2'
不能刪除有外鍵約束的表。sql
drop table Reports
alter table Reports add NewColumn nchar(5) null --新增字段 alter table Reports alter column NewColumn nvarchar(10) --修改字段屬性 exec sp_rename 'Reports.NewColumn','OldColumn'--修改字段名 alter table Reports drop column NewColumn --刪除列
alter table Reports add constraint Name_UQ unique(Name) --新增惟一約束(此非索引) alter table Reports drop constraint Name_UQ --刪除此約束
MSSQL默認主鍵是彙集索引。一個表只能有一個彙集索引(Clustered Index)。數據庫
create index NameIndex on Reports(Name) --新增普通索引(非彙集索引) create unique index Name_UQ on Reports(Name) --新增惟一索引(非彙集索引) exec sp_helpindex Reports --查看錶的索引 drop index Reports.NameIndex --刪除索引 create nonclustered index NameFileIndex on Categories(CategoryName,PictureFile) --建立非彙集索引(組合索引)
當修改表結構時,sql server可能會彈出對話框:bash
不容許保存更改。您所作的更改要求刪除並從新建立如下表。您對沒法從新建立的表進行了更改或者啓用了「阻止保存要求從新建立表的更改」選項。markdown
解決方案:菜單欄->工具->選項->設計器->表設計器和數據庫設計器,右側面板,取消勾選「阻止保存要求從新建立表的更改」。數據庫設計