sql server 數據庫中插入列


 格式 

alter table 表名 
add 字段名 類型 null default 默認值

下面代碼是向 “Table_1 ”表中增加 "Order"字段,類型為int ,可空,默認值是99

alter table Table_1 
add "Order" int null default 99

下面代碼是向 “Table_1 ”表中增加 "age"字段,類型為int ,不能為空

alter table Table_1 
add age int not null

完整的添加,修改,刪除

--添加
alter table Table_1
add msg nchar(10) null
 
--修改
alter table Table_1
alter column msg nvarchar(500) null
 
--刪除
alter table Table_1
drop column msg

 

格式說明

--添加
alter table 表名
add 字段名 類型 是否空
 
--修改
alter table 表名
alter column 字段名 類型 是否空
 
--刪除
alter table 表名
drop column 字段名

 


延伸閱讀

SQL ALTER TABLE 語句

ALTER TABLE 語句

ALTER TABLE 語句用於在已有的表中添加、刪除或修改列。

SQL ALTER TABLE 語法

添加

如需在表中添加列,請使用下面的語法:

ALTER TABLE table_name
ADD column_name datatype

刪除

如需刪除表中的列,請使用下面的語法(請注意,某些數據庫系統不允許這種在數據庫表中刪除列的方式):

ALTER TABLE table_name
DROP COLUMN column_name

修改

要改變表中列的數據類型,請使用下面的語法:

SQL Server / MS Access:

ALTER TABLE table_name
ALTER COLUMN column_name datatype

My SQL / Oracle:

ALTER TABLE table_name
MODIFY COLUMN column_name datatype

Oracle 10G 之后版本:

ALTER TABLE table_name
MODIFY column_name datatype;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM