select count(*) from sys.databases where name='tablec'
如果等于0的话,表示表不存在则创建表,否则表已经存在.
------解决方案--------------------
这样吗:
if not exists(select 1 from sys.tables where name='tablec')
create TABLE tablec(id int identity(1,1),TypeName varchar(100))
else
insert into tablec(TypeName)
values('7')
go
select *
from tablec
/*
id TypeName
1 7
*/
------解决方案--------------------
if not exists(select 1 from sys.tables where name='tableC') -- 语句一
begin
create table tableC -- 语句二
(Id int identity(1,1),
TypeName varchar(100))
end
else
begin
set identity_insert tableC on -- 语句三
insert into tableC(Id,TypeName) select 7,7
set identity_insert tableC off
end
------解决方案-------------------- if not exists(select 1 from sys.tables where name='tablec' and type = 'U')
begin
create table tablec(id int identity(1,1),TypeName varchar(100))
insert into tablec(TypeName) values('7')
end
else
insert into ta