存储过程范围与创建表/视图/索引&选择单个SP

时间:2016-06-09 21:10:38

标签: sql-server sql-server-2008

我有一个sql脚本创建视图/表/索引,有些在每个表/视图创建后用GO语句在一个脚本中选择所有并且我得到错误..可能在一个脚本中将它们全部哈希??? / p>

IF OBJECT_ID('dbo.ABC', 'U') IS NOT NULL 
    DROP TABLE dbo.ABC; 
GO

select v.*
INTO dbo.ABC
from dbo.BC v

GO

CREATE  NONCLUSTERED INDEX IX_ABC_ID  ON dbo.ABC ([ID])

GO

GO

CREATE VIEW [dbo].[vABC] AS
SELECT [ID]
      ,[Description]
      ,[Name]
  FROM [dbo].[NewDRGTable]
GO

1 个答案:

答案 0 :(得分:0)

你可以对每个部分使用EXEC语句(不要忘记逃避撇号):

EXEC('IF OBJECT_ID(''dbo.ABC'', ''U'') IS NOT NULL 
DROP TABLE dbo.ABC;')