我有一个名为Master_Table
的主表,该主表中的列和值如下:
| ID | Database | Schema | Table_name | Common_col | Value_ID |
+-------+------------+--------+-------------+------------+----------+
| 1 | Database_1 | Test1 | Test_Table1 | Test_ID | 1 |
| 2 | Database_2 | Test2 | Test_Table2 | Test_ID | 1 |
| 3 | Database_3 | Test3 | Test_Table3 | Test_ID2 | 2 |
我还有另一个Value_Table
,其中包含需要删除的值。
| Value_ID | Common_col | Value |
+----------+------------+--------+
| 1 | Test_ID | 110 |
| 1 | Test_ID | 111 |
| 1 | Test_ID | 115 |
| 2 | Test_ID2 | 999 |
我需要构建一个查询以创建一个SQL查询,以从Master_Table
中提供的表中删除该值,该表的数据库和架构信息在同一行中提供。我需要参考删除记录的列在主表的Common_col
列中,我需要选择的值在Value
的{{1}}列中。
我的查询结果应创建如下查询:
从Database_1.Test1.Test_Table1中删除,其中Test_ID = 110; 或
从数据库_1.Test1.Test_Table1中删除(110,111,115)中的Test_ID;
这些查询应该在循环中,以便我可以从主表中提供的所有数据库和表中删除所有行。