当前位置: 代码迷 >> Sql Server >> 关于动态建表的一个有关问题
  详细解决方案

关于动态建表的一个有关问题

热度:67   发布时间:2016-04-25 01:04:35.0
关于动态建表的一个问题
  Set @CreateSQL='Create Table '+ @TableName + 
'(    [OpeningDirection]       NCHAR (1)      NOT NULL,
    CONSTRAINT [CK_'+@TableName+'_OpeningDirection] CHECK ([OpeningDirection]='+'多'+' OR OpeningDirection='+'空'+'))'
Exec(@CreateSQL)


@TableName是传过来的表名,check这个地方总是报错,求指教
------最佳解决方案--------------------
  Set @CreateSQL='Create Table '+ @TableName +  
'(    [OpeningDirection]       NCHAR (1)      NOT NULL, 
    CONSTRAINT [CK_'+@TableName+'_OpeningDirection] CHECK ([OpeningDirection]='+'''多'''+' OR OpeningDirection='+'''空'''+'))'
Exec(@CreateSQL)
  相关解决方案