0
我不相信我的标题能够准确反映我的问题,但这里是我有:如何循环访问SQL表?
DECLARE @ListOfTables TABLE(
RowID INT NOT NULL PRIMARY KEY IDENTITY(1,1)
, TableName VARCHAR(200)
)
DECLARE @RowsToProcess INT
DECLARE @CurrentRow INT
DECLARE @TableName VARCHAR(200)
INSERT INTO @ListOfTables (TableName)
VALUES ('Books')
INSERT INTO @ListOfTables (TableName)
VALUES ('Magazines')
INSERT INTO @ListOfTables (TableName)
VALUES ('Essays')
SET @RowsToProcess = @@ROWCOUNT
SET @CurrentRow = 0
我希望再通过这个表圈和删除。
WHILE @CurrentRow < @RowsToProcess
BEGIN
SET @CurrentRow = @CurrentRow+1
SELECT @TableName = TableName
FROM @ListOfTables
WHERE RowID = @CurrentRow
DELETE FROM @TableName
END
实际上,我的删除不只是删除表 - 它有特定的标准。为了演示目的,我简化了它。
我来到这里的错误是:Must declare the variable '@TableName'.
我搬到成WHILE循环,我收到了同样的错误。
我能在这里做什么?是否有可能做我想做的事情?
啊!正是我需要的。谢谢。 – Rail24 2014-11-06 22:01:27
请注意您获取@TableName的数据的位置。你可以打开自己的SQL注入。 – SQLburn 2014-11-06 23:12:51