sql server 資料庫中插入列

2021-10-18 03:28:53 字數 2246 閱讀 1204

格式 

--增加列

alter table 表名

add 欄位名 型別 null default 預設值

--給列增加注釋

execute sp_addextendedproperty 'ms_description',

'列的注釋',

'user', 'dbo', 'table', '表名', 'column', '列名'

為sql server表中的列新增/修改/刪除注釋屬性sp_addextendedproperty、sp_updateextendedproperty、sp_dropextendedproperty_橙cplvfx-技術踩坑記-csdn部落格

為sql server表中的列新增/修改/刪除注釋屬性 sp_addextendedproperty、sp_updateextendedproperty、sp_dropextendedproperty

下面**是向 「table_1 」表中增加 "order"字段,型別為int ,可空,預設值是99

--增加列

alter table table_1

add "order" int null default 99

--給列增加注釋

execute sp_addextendedproperty 'ms_description',

'排序',

'user', 'dbo', 'table', 'table_1', 'column', 'order'

下面**是向 「table_1 」表中增加 "age"字段,型別為int ,不能為空

--增加列

alter table table_1

add age int not null

--給列增加注釋

execute sp_addextendedproperty 'ms_description',

'年齡',

'user', 'dbo', 'table', 'table_1', 'column', 'age'

--新增

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 欄位名

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;

sql server 跨資料庫插入資料

公司專案改造,需要將以前的資料庫表記錄匯入到新的資料庫表中,結構不是完全相同。在跨庫的過程中,學到了不少東西。原來sqlserver 還有 鏈結伺服器的功能呢。建立鏈結伺服器exec sp addlinkedserver itsv sqloledb 遠端伺服器名或ip位址 exec sp addli...

SQL server 插入不同IP的資料庫

如果有乙個ip為 192.168.100.1 另乙個ip為 192.168.100.78 首先使用在192.168.100.1中資料庫執行 exec sp addlinkedserver 192.168.100.78 下面是sp addlinkedserver 解釋 建立乙個鏈結的伺服器,使其允許對...

資料庫中插入記錄

把一張表中的資料插入資料庫中 現在,我們將建立乙個html表單 通過它我們可以向 person 表中加入新的記錄。下面演示這個html表單 在上述案例中,當乙個使用者點選html表單中的 提交submit 按鈕後,表單中的資料會傳送到 insert.php insert.php 檔案與資料庫建立連線...