添加字段的SQL語句的寫法: 通用式: 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 的表示字段允許零長 2. 修改表: A. 重命名表: EXEC sp_rename 'oldname','newname' B. 修改列屬性: ALTER TABLE 學生信息 ALTER COLUMN 姓名 varchar(20) NOT NULL C. 添加列: ALTER TABLE 學生信息 ADD 家庭住址 nvarchar(20) NULL D. 刪除列: ALTER TABLE 學生信息 DROP COLUMN 家庭住址 D. 修改列名: exec sp_rename '表名.[字段原名]','字段新名','column' 3. 復制表: A. 復制整張表: select * into new_table from old_table B. 復制表結構: select * into new_table from old_table where 1=2 B. 復制表內容: insert into new_tab select * from old_table 4. 修改identity列 自增列不能直接修改,必須將原有ID列刪除,然后重新添加一列具有identity屬性的ID字段。比如你要修改的字段名為ID: alter table 表名 drop column ID alter table 表名 add ID int identity(1,1)