当前位置: 代码迷 >> Sql Server >> 简单EXISTS有关问题!高手解救........多谢
  详细解决方案

简单EXISTS有关问题!高手解救........多谢

热度:153   发布时间:2016-04-27 19:25:13.0
简单EXISTS问题!高手解救........谢谢
IF NOT EXISTS (?????????)
exec( 'create table [email protected][email protected]+ '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float )')
这样写如果不存在,[email protected][email protected](字符型+int)

------解决方案--------------------
SQL code
if object_id('数据库名..表名') is not null   drop table 表名else   create table ....go
------解决方案--------------------
declare @tb varchar(10)
declare @curY int
declare @sql varchar(1000)

select @tb='a'
select @cury=1
select @sql='if not exists (select * from dbo.sysobjects where id = object_id(N''[dbo].[[email protected]+convert(varchar(10),@cury)+']'') and OBJECTPROPERTY(id, N''IsUserTable'') = 1)'
+' create table [email protected]+convert(varchar(10),@cury)+ '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float ) '
exec(@sql)

------解决方案--------------------
SQL code
if not exists(select * from sys.sysobjects where id=object_ID(@[email protected]))exec(  'create table   [email protected][email protected]+  '(dt datetime,tag int,type int,mval real,mmax real,mmin real,mavg real,msum float ) ')
  相关解决方案