条件检测的sql代码
检测数据库a是否存在表b,如果不存在的话就新建一个表。
求代码?
------解决方案--------------------if not exists (select * from sysobjects where xtype= 'U ' and name= 'b ')
create table a.dbo.b(
...
)
------解决方案-------------------- use tempdb
if exists (select * from dbo.sysobjects where id = object_id(N '[dbo].[Table_Test] ') and OBJECTPROPERTY(id, N 'IsUserTable ') = 1)
begin
print N '表存在 '
end
else
begin
CREATE TABLE [dbo].[Table_Test] (
[Id_int] [int] IDENTITY (1, 1) NOT NULL ,
[test] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
end