Tag Archives: T-SQL;SQL Tips;SQL Tricks;SQL Automation

Script to auto-add surrogate primary keys

Here’s an example of how to use information_schema tables to automatically add clustered primary surrogate keys select ‘alter table ‘ +  table_name + ‘ add ‘ + table_name + ‘_Id int identity;’ from INFORMATION_SCHEMA.tables t where not exists (select 0from … Continue reading

Posted in SQL Server | Tagged | Leave a comment