*************************** --判断数据库是否存在 IF EXISTS (SELECT * FROM MASTER..sysdatabases WHERE NAME = '库名') PRINT 'exists ' else PRINT 'not exists' *************************** -- 判断要创建的表名是否存在 IF EXISTS (Select * From sysObjects Where Name ='表名' And Type In ('S','U')) PRINT 'exists' ELSE PRINT 'not exists' GO *************************** --判断要创建临时表是否存在 If Object_Id( 'Tempdb.dbo.#Test') Is Not NULL--#Test 为临时表名 Begin print '存在 ' End Else Begin print '不存在 ' End *************************** -- 判断要创建的存储过程名是否存在 IF EXISTS (Select * From sysObjects Where Name ='存储过程名' And Type In ('S','P')) PRINT 'exists' ELSE PRINT 'not exists' GO *************************** -- 判断列名是否存在 IF EXISTS (SELECT O.NAME AS 表名,C.NAME AS 列名 FROM SYSOBJECTS O INNER JOIN SYSCOLUMNS C ON O.ID=C.ID WHERE O.NAME= '表名' AND C.NAME = '列名') SELECT 'EXISTS' ELSE SELECT 'NOT EXISTS' *************************** 1.增加列: alter table tableName add columnName varchar(30) 2.修改列类型: alter table tableName alter column columnName varchar(4000) 3.修改列的名称: EXEC sp_rename 'tableName.column1' , 'column2' (把表名为tableName的column1列名修改为column2) 4.删除列: alter table tableName drop column columnName ***************************