I use PDW and I have query which creates a list of tables to be dropped.
我使用PDW,我有查询,它创建一个要删除的表列表。
Table Q :
表Q:
TableName
---------
a
b
c
d
e
a,b,c,d,e
are the list of tables in the database which should be dropped.
a,b,c,d,e是数据库中应删除的表的列表。
I want to write a dynamic sql query which will drop the tables a
to e
listed in table Q
without any human intervention.
我想编写一个动态的SQL查询,它将删除表Q中列出的表,而无需任何人工干预。
Is it possible?
可能吗?
1 个解决方案
#1
1
You can use the following dynamic sql to achieve this: (assuming that the table name is Table Q
and the column name is TABLE_NAME
)
您可以使用以下动态sql来实现此目的:(假设表名是表Q,列名是TABLE_NAME)
DECLARE @strQuery as varchar(MAX)
SET @strQuery = ''
SELECT @strQuery = @strQuery + 'DROP TABLE [' + TABLE_NAME + '];' FROM [Table Q]
EXEC(strQuery)
#1
1
You can use the following dynamic sql to achieve this: (assuming that the table name is Table Q
and the column name is TABLE_NAME
)
您可以使用以下动态sql来实现此目的:(假设表名是表Q,列名是TABLE_NAME)
DECLARE @strQuery as varchar(MAX)
SET @strQuery = ''
SELECT @strQuery = @strQuery + 'DROP TABLE [' + TABLE_NAME + '];' FROM [Table Q]
EXEC(strQuery)