我需要生成像'test_table_1','test_table_2'這樣的表......我做錯了什麼?如何在MS SQL中生成表格?
declare @i int = 1;
declare @i_str varchar(1024);
declare @table VARCHAR(1024);
while (@i < 500)
BEGIN
SET @i = @i + 1;
SET @table = 'TEST_TABLE_' + convert(varchar, @i);
IF NOT EXISTS(SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = @table)
CREATE TABLE @table (
\t ID INT,
\t userid INT,
\t name TEXT,
\t last_name TEXT,
\t country TEXT,
\t city TEXT
)
END
錯誤:近@table 語法不正確。期待'。',ID或QUOTED_ID
首先不要用這種方式初始化declare @i int = 1;讓它聲明@i int,並設置@i = 1; – Reena