新建表sql
create table [表名]
(
[自動編號字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default \'默認值\' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)數據庫
刪除表函數
Drop table [表名]spa
插入數據日誌
INSERT INTO [表名] (字段1,字段2) VALUES (100,\'51WINDOWS.NET\')ci
刪除數據it
DELETE FROM [表名] WHERE [字段名]>100io
更新數據table
UPDATE [表名] SET [字段1] = 200,[字段2] = \'51WINDOWS.NET\' WHERE [字段三] = \'HAIWA\'object
新增字段
ALTER TABLE [表名] ADD [字段名] NVARCHAR (50) NULL
刪除字段
ALTER TABLE [表名] DROP COLUMN [字段名]
修改字段
ALTER TABLE [表名] ALTER COLUMN [字段名] NVARCHAR (50) NULL
重命名錶(Access 重命名錶,請參考文章:在Access數據庫中重命名錶)
sp_rename \'表名\', \'新表名\', \'OBJECT\'
新建約束
ALTER TABLE [表名] ADD CONSTRAINT 約束名 CHECK ([約束字段] <= \'2000-1-1\')
刪除約束
ALTER TABLE [表名] DROP CONSTRAINT 約束名
新建默認值
ALTER TABLE [表名] ADD CONSTRAINT 默認值名 DEFAULT \'51WINDOWS.NET\' FOR [字段名]
刪除默認值
ALTER TABLE [表名] DROP CONSTRAINT 默認值名
刪除Sql Server 中的日誌,減少數據庫文件大小
dump transaction 數據庫名 with no_log
backup log 數據庫名 with no_log
dbcc shrinkdatabase(數據庫名)
exec sp_dboption \'數據庫名\', \'autoshrink\', \'true\'
\\\'添加字段通用函數
Sub AddColumn(TableName,ColumnName,ColumnType)
Conn.Execute(\"Alter Table \"&TableName&\" Add \"&ColumnName&\" \"&ColumnType&\"\")
End Sub
\\\'更改字段通用函數
Sub ModColumn(TableName,ColumnName,ColumnType)
Conn.Execute(\"Alter Table \"&TableName&\" Alter Column \"&ColumnName&\" \"&ColumnType&\"\")
End Sub
\\\'檢查表是否存在
sql=\"select count(*) as dida from sysobjects where id = object_id(N\'[全部者].[表名]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1\"
set rs=conn.execute(sql)
response.write rs(\"dida\")\'返回一個數值,0表明沒有,1表明存在
判斷表的存在
select * from sysobjects where id = object_id(N\'[dbo].[tablename]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1
某個表的結構
select * from syscolumns where id = object_id(N\'[dbo].[你的表名]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1