SQL中如何在表中新增欄位,在資料表中新增一個欄位的SQL語句怎麼寫

時間 2021-10-25 03:13:21

1樓:我愛數學

alter table tablename1

add | alter [column] fieldname1

fieldtype [(nfieldwidth [, nprecision])]

[null | not null]

[check lexpression1 [error cmessagetext1]]

[default eexpression1]

[primary key | unique]

[references tablename2 [tag tagname1]]

[nocptrans]

例:alter table customer add column fax c(20) null

你的可能是日期時間型的列?

alter table 表名 add column sendtimec datetime

補充:你要什麼時間?新增加的列當然沒有數值了。

你可以設定預設值

alter table 表名 add column sendtime datetime default datetime()

“空上**”是什麼?

修改:alter table 表名 add column sendtime datetime default getdate()

修改已存在資料行的該列值

update 表名 set sendtime=getdate()

2樓:辰思

資料表中新增一個欄位的標準sql語句寫法為:

alter table 表名 add (欄位 欄位型別) [ default '輸入預設值'] [null/not null] ;

舉例:alter table employee add spbh varchar(20) not null default 0

意思就是在表employee 中加入 欄位spbh,該欄位的型別是varchar,大小20,並且不允許為空,初始預設值是0。

擴充套件資料:

其他常用sql語句:

1、修改資料表中某項欄位屬性,為其新增備註。

語句格式:comment on column 庫名.表名.欄位名 is '輸入的備註';

示例: 我要在ers_data庫中 test表 document_type欄位新增備註,則sql語句為:

comment on column ers_data.test.document_type is '檔案型別';

2、修改資料表中某欄位型別。

語句格式:alter table 表名 modiy (欄位 欄位型別 [default '輸入預設值' ] [null/not null] ,欄位 欄位型別 [default '輸入預設值' ] [null/not null] ); 修改多個欄位用逗號隔開。

示例:想要修改一個teacher教師表中欄位辦公室classroom的型別為char(20),且預設值“辦公室”,則對應sql為:

alter table teacher alter column classroom varchar(20) not null default "辦公室";

3、刪除資料表中的某欄位。

語句格式:alter table 表名 drop (欄位);

示例:刪除表student中的欄位age,可以用如下sql:

alter table student drop age;

在資料表中新增一個欄位的sql語句怎麼寫

3樓:匿名使用者

資料表中新增一個欄位的標準sql語句寫法為:

alter table  表名  add (欄位  欄位型別)  [ default  '輸入預設值']  [null/not null]  ;

舉例:alter table employee  add  spbh varchar(20) not null default 0

意思就是在表employee 中加入 欄位spbh,該欄位的型別是varchar,大小20,並且不允許為空,初始預設值是0。

擴充套件資料:

其他常用sql語句:

1、修改資料表中某項欄位屬性,為其新增備註。

語句格式:comment on column  庫名.表名.欄位名 is  '輸入的備註';

示例: 我要在ers_data庫中  test表 document_type欄位新增備註,則sql語句為:

comment on column ers_data.test.document_type is '檔案型別';

2、修改資料表中某欄位型別。

語句格式:alter table 表名  modiy (欄位  欄位型別  [default '輸入預設值' ] [null/not null]  ,欄位  欄位型別  [default '輸入預設值' ] [null/not null] ); 修改多個欄位用逗號隔開。

示例:想要修改一個teacher教師表中欄位辦公室classroom的型別為char(20),且預設值“辦公室”,則對應sql為:

alter table teacher alter column classroom varchar(20) not null default "辦公室";

3、刪除資料表中的某欄位。

語句格式:alter table  表名  drop (欄位);

示例:刪除表student中的欄位age,可以用如下sql:

alter table student drop age;

4樓:匿名使用者

通用式: alter table [表名] add [欄位名] 欄位屬性 default 預設值 default 是可選引數

增加欄位: alter table [表名] add 欄位名 smallint default 0 增加數字欄位,整型,預設值為0

alter table [表名] add 欄位名 int default 0 增加數字欄位,長整型,預設值為0

alter table [表名] add 欄位名 single default 0 增加數字欄位,單精度型,預設值為0

alter table [表名] add 欄位名 double default 0 增加數字欄位,雙精度型,預設值為0

alter table [表名] add 欄位名 tinyint default 0 增加數字欄位,位元組型,預設值為0

alter table [表名] add 欄位名 text [null] 增加備註型欄位,[null]可選引數

alter table [表名] add 欄位名 memo [null] 增加備註型欄位,[null]可選引數

alter table [表名] add 欄位名 varchar(n) [null] 增加變長文字型欄位大小為n(1~255)

alter table [表名] add 欄位名 char [null] 增加定長文字型欄位大小固定為255

alter table [表名] add 欄位名 datetime default 函式增加日期型欄位,其中函式可以是now(),date()等,表示預設值

(上面都是最常用的,還有其他的屬性,可以參考下面的資料型別描述)

刪除欄位: alter table [表名] drop 欄位名

修改變長文字型欄位的大小:alter table [表名] alter 欄位名 varchar(n)

刪除表: drop table [表名]

建立表:

sql="create table [表名] ([欄位1,並設定為主鍵] int identity (1, 1) not null constraint primarykey primary key,"&

"[欄位2] varchar(50),"&

"[欄位3] single default 0,"&

"[欄位4] varchar(100) null,"&

"[欄位5] smallint default 0,"&

"[欄位6] int default 0,"&

"[欄位7] date default date(),"&

"[欄位8] int default 1)"

conn.execute sql

有null 的表示欄位允許零長

以上內容**於www.viiboo.cn具體可參見

5樓:

主要通過修改表 增加列的方式,如下sql語句修改表,增加一個整型

alter table [表名]

add [列名] int not null

6樓:匿名使用者

alter table 表 add column 欄位名 int(型別) not null default 0 (約束預設值)

7樓:匿名使用者

alter table 表名 add 欄位名 型別

alter table 表名 add 欄位名 型別 default 預設值

8樓:匿名使用者

alter table 表名 add 欄位名 欄位型別;

9樓:匿名使用者

alter table [表名] add [新列名] 型別及列的約束

比如:alter table *** add newcol int not null default(0)

用sql語句在表中增加一個欄位

10樓:創作者

alter table 表名 add columns 欄位名 約束條件

11樓:匿名使用者

alter table 表名 add 欄位名 約束條件

12樓:

我來回答:

alter table rsda add column 獎金 int

或者alter table rsda add 獎金 int

如何在資料庫中設定id欄位為主鍵

alter table 表名 add constraint myck primary key id 首先你要確保表裡沒有主鍵,另外id列上沒有其他約束 create table t1 id int identity 1,1 primary key 就是主鍵了,自動增長 或者在當前表名上反鍵,修改 然...

SQL中update語句新增表中資料時,表名是變數,語句要怎麼寫

使用exec sql語句 例 使用變數拼接sql語句,然後用exec執行declare table varchar 200 declare sql varchar 200 set table aaa set sql select from tableexec sql 例中的變數 table 即傳遞表...

如何在中新增頁碼,如何在word中新增頁碼?

要看新增什麼樣的文件了,可以從word裡選單欄插入 頁碼 回答滑鼠雙擊第一頁頁面底部萊 開啟要加頁碼的word文件,用滑鼠雙擊第一頁頁面底部,點選選單欄中的 頁碼 選擇設定頁碼格式後設定起始頁碼為1 選擇 設定頁碼格式 設定 起始頁碼 為1,點選 確定 選擇頁面底端中的普通數字 再點選 頁碼 下方的...