ACCESSAccess sql语句创立表及字段类型

     Set clx = Nothing
     Set cat = Nothing
     cn.Close
     Set cn = Nothing End Sub

除去约束:
Alter TABLE [表名] Drop CONSTRAINT 约束名

”—- DataTypeEnum Values —- 
Const adEmpty = 0
Const adTinyInt = 16
Const adSmallInt = 2
Const adInteger = 3
Const adBigInt = 20
Const adUnsignedTinyInt = 17
Const adUnsignedSmallInt = 18
Const adUnsignedInt = 19
Const adUnsignedBigInt = 21
Const adSingle = 4
Const adDouble = 5
Const adCurrency = 6
Const adDecimal = 14
Const adNumeric = 131
Const adBoolean = 11
Const adError = 10
Const adUserDefined = 132
Const adVariant = 12
Const adIDispatch = 9
Const adIUnknown = 13
Const adGUID = 72
Const adDate = 7
Const adDBDate = 133 
Const adDBTime = 134
Const adDBTimeStamp = 135
Const adBSTR = 8
Const adChar = 129
Const adVarChar = 200
Const adLongVarChar = 201
Const adWChar = 130
Const adVarWChar = 202
Const adLongVarWChar = 203
Const adBinary = 128
Const adVarBinary = 204
Const adLongVarBinary = 205
Const adChapter = 136
Const adFileTime = 64
Const adPropVariant = 138
Const adVarNumeric = 139
Const adArray = &H2000

字段类型对应数值

创造一张空表: Sql=”Create TABLE [表名]”

call GenAutoIncrementFld

=======================================

 

删去字段: 
sql=”alter table [表名] drop [字段名]”

<% 
session(“tablen”)=”news” 
‘news是已存在的表名 
session(“fieldsn”)=”c” 
‘要加上的字段名
connectionstring=”provider=microsoft.jet.oledb.4.0;data
source=”&server.MapPath(“data/qq.mdb”) 
set conn=server.createobject(“adodb.connection”) 
conn.OPEN connectionstring 
jhsql = ” Alter Table “&session(“tablen”)&” add column
“&session(“fieldsn”)&” real ” 
conn.execute(jhsql)
%>

tblnam.Name = “Test”      
clx.ParentCatalog = cat

   
clx.Type = 3      
clx.Name = “Id”     
clx.Properties(“AutoIncrement”) = true      
tblnam.Columns.Append clx      
tblnam.Columns.Append “DataField”,130,20      
cat.Tables.Append tblnam

新建默许值:
Alter TABLE [表名] ADD CONSTRAINT 默许值名 DEFAULT ‘Gziu.CoM’ FO陆风X8
[字段名]

================================

以下字段为无编码字段(NChar、NVarchar、NText型)
8,128,130,202,203,204,205
以下字段为按近来系统内码编码的字段(Asp中可用CodePage=936考订为gb2312内码)
129,200,201

扭转数据表,添加字段,在那之中id字段为活动扩大,测试通过~~

cn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\网站制作\asp操作mdb\db\test.mdb”      
Set cat.ActiveConnection = cn

 

=======================================

创设一张有字段的表: Sql=”Create TABLE [表名]([字段名1] MEMO NOT
NULL, [字段名2] MEMO, [字段名3] COUNTER NOT NULL, [字段名4]
DATETIME, [字段名5] TEXT(200), [字段名6] TEXT(200))

去除默许值:
Alter TABLE [表名] Drop CONSTRAINT 暗中认可值名

Sub GenAutoIncrementFld() 
set cn=server.CreateObject(“ADODB.Connection”) 
set clx=server.CreateObject(“ADOX.Column”) 
set cat=server.CreateObject(“ADOX.Catalog”) 
set tblnam=server.CreateObject(“ADOX.Table”)

conn.open connstr sql=”alter table [tablename] add hehe char(20)”
conn.execute(sql) response.write(“添加事业有成”)

2 : “SmallInt”,                 // 整型    
3 : “Int”,                 // 长整型    
4 : “Real”,                 // 单精度型    
5 : “Float”,                 // 双精度型    
6 : “Money”,                 // 货币    
7 : “DateTime”,                 // 日期时间 
11 : “Bit”,                 // 是否 
13 : “TimeStamp”, 
17 : “TinyInt”,                 // 字节 
72 : “UniqueIdentifier”,         // 同步复制 ID 
128 : “Binary”, 
129 : “Char”, 
130 : “NChar”, 
131 : “Decimal”,                 // 小数 
133 : “DateTime”, 
135 : “SmallDateTime”, 
200 : “VarChar”, 
201 : “Text”, 
202 : “VarChar”,                 // 文本 
203 : “Text”,                 // 备注 
204 : “Binary”,                 // 二进制 
205 : “Image”                 // OLE 对象

ACCESS新建数据库和表还不不难,有了表字段开头化就更简明

删除表: 
Sql=”Drop table [表名]”

修改字段:
Alter TABLE [表名]ACCESS, Alter COLUMN [字段名] 类型(大小) NULL

新建约束:
Alter TABLE [表名] ADD CONSTRAINT 约束名 CHECK ([自律字段] <=
‘2007-1-1’)

字段类型:   

在存活的表中扩张字段: 
Sql=”alter table [表名] add column [字段名] varchar(200)”

修改字段类型: 
Sql=”alter table [表名] Alter COLUMN 字段名]   varchar(50)”

===================================

相关文章