sql 資料庫 sql 語句一些操作

來源:互聯網
上載者:User

好長時間沒寫文章了,

今天練習了一些 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','欄位'

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.