I am trying to create a procedure in which I create a variable -> @table_name
and assign a select, that gets a list of tables names from sys.table
.
Then I need to insert the @table_name
to line with delete and go into each table from the list and delete records in them.
I will be grateful for help.
create procedure Test
as
declare @table_name = (select [name]
from sys.tables
where [name] like ('%x1') or [name] like ('%x2'))
-- how I can do the iteration???
delete [@table_name]
where id in (select id
from [@table_name]
where column_2 like ('%.%'))