資料庫--添加欄位語句,--欄位語句

來源:互聯網
上載者:User

資料庫--添加欄位語句,--欄位語句



本文由 書畫小說軟體 整理髮布 內容與本軟體無關 更愜意的讀、更舒心的寫、更輕鬆的發布









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

執行個體:

alter table 班級表2 add  COLUMN 小組 int 0

以下例子可能確實column

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 的表示欄位允許零長




書畫小說軟體 製作更愜意的讀、更舒心的寫、更輕鬆的發布

相關文章

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.