Is there a way to clone the table definition from an existing table and recreate as a table variable?
DECLARE @TempTable1 TABLE (ID INT, Description VARCHAR(256))
I need to recreate a set of tables with same number of columns and definitions without repeating the DECLARE TABLE
statement.
This process is available on MySQL as below.
CREATE TABLE TempTable1 LIKE TempTableMain;
Is it possible to do this is Microsoft SQL Server?
Please note that the actual scenario contains more that 60 columns in the @TempTable
and need to create more than 10 instances from the original table.
I am not talking about data insertion or SELECT
ion from another table as below. I need to create the table definition.
DECLARE @TempTable TABLE(ID INT, Description VARCHAR(100))
INSERT INTO @TempTable
VALUES (1, 'Test1'), (1, 'Test1');
SELECT *
INTO @TempTable2
FROM @TempTable1
SELECT * FROM @TempTable2