Creating SQL table using dynamic variable name

前端 未结 5 954
滥情空心
滥情空心 2021-02-05 17:23

I want to create backup SQL tables using variable names.

something along the lines of

DECLARE @SQLTable Varchar(20) 
SET @SQLTable = \'SomeTableName\' +         


        
5条回答
  •  失恋的感觉
    2021-02-05 17:49

    You should look into using synonyms:

    -- Create a synonym for the Product table in AdventureWorks2008R2. CREATE SYNONYM MyProduct FOR AdventureWorks2008R2.Production.Product; GO

    -- Query the Product table by using the synonym. USE tempdb; GO SELECT ProductID, Name FROM MyProduct WHERE ProductID < 5; GO

    http://msdn.microsoft.com/en-us/library/ms177544.aspx

提交回复
热议问题