天天看點

常用SQL語句-Part1

1. 向某個資料表中,增加一列。

--Oracle
Alter Table table_name Add column_name colomn_type;
Commit;
           
--Sql Server
Alter Table table_name Add column_name colomn_type;
GO
           

注:無差別。

2. 更新某個資料表中某一列的類型。

--Oracle
Alter Table table_name Modify column_name colomn_type_new;
Commit;
           
--Sql Server
Alter Table table_name Alter Column column_name colomn_type_new;
GO
           

注:"Modify" V.S. "Alter Column"。

3. 删除某個資料表中的某一列。

--Oracle
Alter Table table_name Drop Column column_name;
Commit;
           
--Sql Server
Alter Table table_name Drop Column column_name;
GO
           

注:無差別。

4. 更新某個資料表中某一列的名稱。

注:要先将該列删除,然後,重建立立。

5. 增加資料表表名注釋

--Oracle
Comment on Table table_name is '表名稱';
Commit;
           
--Sql Server
--未知
           

6. 增加資料表某一列的注釋

--Oracle
Comment on Column table_name.column_name  is '列名';
Commit;
           
--Sql Server
EXECUTE sp_addExtendedProperty N'MS_Description', '列注釋', N'user', N'使用者名', N'table', N'表名', N'column', N'列名';
GO