I have a database of tables, and i want to iterate through each table in 3 different schema, one schema at a time.
I figure that i'll need something along the lines of :
DECLARE @tableName varchar(50)
DECLARE @schemaName varchar(50)
For now lets call the schemas "A" "B" and "C".
I can get a list of the tables from each schema using :
SELECT t.name
FROM sys.tables AS t
INNER JOIN sys.schemas AS s
ON t.[schema_id] = s.[schema_id]
WHERE s.name = N'schema_name';
but im not sure how to iterate through that list (id like to insert values in to every table one by one, and they are dependent on the datatype of the columns of the tables so i cant just do a blanket insert into all statement).
CURSOR. Have a read through the documentation: msdn.microsoft.com/en-us/library/ms180169.aspx