SQL Serverテーブル構造の変更
2933 ワード
指定したテーブル構造の表示
テーブル名の変更
データテーブルの削除
外部キー制約のあるテーブルは削除できません.
テーブルフィールド
フィールド制約
フィールド索引
MSSQLのデフォルトのプライマリ・キーは集計インデックスです.1つのテーブルには1つの集約インデックス(Clustered Index)しかありません.
exec sp_help Reports
テーブル名の変更
exec sp_rename 'Reports','Reports2'
データテーブルの削除
外部キー制約のあるテーブルは削除できません.
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のデフォルトのプライマリ・キーは集計インデックスです.1つのテーブルには1つの集約インデックス(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) -- ( )