好長時間沒寫文章了,
今天練習了一些 sql語句動作表 索引, 列 等 做個記錄
建立索引 和建立約束格式不一樣 不要混淆
建立表
create table plane
(
id int identity(1,1) not null ,
planeid int not null,
persion nvarchar (50) not null,
addtime datetime default getdate() not null
constraint pk_plane primary key clustered( id asc) --id 為主鍵 並為叢集索引 sql 的寫法 其他資料庫沒試過
)
建立非聚簇索引 nonclustered 聚簇索引 clustered
create nonCLUSTERED index idx_plane on plane(planeid)
刪除索引
drop index idx_plane on plane
添加列
alter table plane add num int not null default 0
修改列 類型 ,列在有約束,或索引的情況下 應先刪除索引或約束
alter table plane alter column num varchar(100)
添加預設值約束
alter table plane add constraint df_planename default('fd') for planename
刪除 約束
alter table plane drop df_planename
下班是抄別人的 做個記錄
--為表添加描述資訊
EXECUTE sp_addextendedproperty N'MS_Description', '人員資訊表', N'user', N'dbo', N'table', N'表', NULL, NULL
--為欄位a1添加描述資訊
EXECUTE sp_addextendedproperty N'MS_Description', '姓名', N'user', N'dbo', N'table', N'表', N'column', N'欄位'
--為欄位a2添加描述資訊
EXECUTE sp_addextendedproperty N'MS_Description', '性別', N'user', N'dbo', N'table', N'表', N'column', N'欄位'
--更新表中列a1的描述屬性:
EXEC sp_updateextendedproperty 'MS_Description','欄位1','user',dbo,'table','表','column','欄位'
--刪除表中列a1的描述屬性:
EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','表','column','欄位'