DECLARE @scriptstr VARCHAR(MAX)= 'Use InmateTrustfundx' + CHAR(13) + CHAR(10) DECLARE @guids TABLE ( tbl VARCHAR(100) , col VARCHAR(100) ) DECLARE @tables TABLE ( tbl VARCHAR(100) ) DECLARE @cols TABLE ( col VARCHAR(100) ) DECLARE @tbl VARCHAR(100) DECLARE @col VARCHAR(100) INSERT INTO @guids SELECT tables.name , col.name FROM sys.columns col JOIN sys.tables ON col.object_id = tables.OBJECT_ID WHERE system_type_id = 175 AND max_length = 36 ORDER BY tables.name , column_id SELECT * FROM @guids INSERT INTO @tables SELECT DISTINCT tbl FROM @guids SELECT * FROM @tables WHILE EXISTS ( SELECT * FROM @tables ) BEGIN SELECT TOP 1 @tbl = tbl FROM @tables SELECT @scriptstr = @scriptstr + CHAR(13) + CHAR(10) + 'Alter Table ' + @tbl + CHAR(13) + CHAR(10) DELETE FROM @cols INSERT INTO @cols SELECT col FROM @guids WHERE tbl LIKE @tbl + '%' WHILE EXISTS ( SELECT * FROM @cols ) BEGIN SELECT TOP 1 @col = col FROM @cols SELECT @scriptstr = @scriptstr + 'Alter column ' + @col + ' uniqueidentifier' + CHAR(13) + CHAR(10) DELETE FROM @cols WHERE col LIKE @col + '%' END DELETE FROM @tables WHERE tbl LIKE @tbl END RETURNOutput on the small test db (will probably stick in a go between each alter table and maybe keep the object_id of the table so I don't need the LIKE stuff, but this is definitely proof of concept)
Use InmateTrustfundx Alter Table account_credits Alter column cid uniqueidentifier Alter column cinmates_id uniqueidentifier Alter Table account_debits Alter column cpurchases_id uniqueidentifier Alter column cshiftlog_id uniqueidentifier Alter column cbank_checks_id uniqueidentifier Alter column cpayout_requests_id uniqueidentifier Alter column cexports_id uniqueidentifier Alter column ctransfer_batches_id uniqueidentifier Alter column cycreditedamt_exports_id uniqueidentifier Alter column cycreditedamt_shiftlogid uniqueidentifier Alter column cbookings_id uniqueidentifier Alter column cacct_events_id uniqueidentifier