No Primary Keys ? No Problem !!!
Declare @prefix as nvarchar(11);
Declare @suffix1 as nvarchar(100);
Declare @suffix2 as nvarchar(100);
set @prefix=’ALTER TABLE’;
set @suffix1= ‘ ADD ID int NOT NULL IDENTITY(1,1) CONSTRAINT pk_’;
set @suffix2= ‘ PRIMARY KEY NONCLUSTERED ‘;
select distinct(sys.tables.name) , @prefix +’ ‘+ sys.tables.name + @suffix1+sys.tables.name+@suffix2
from sys.tables inner join syscolumns on
sys.tables.object_id=syscolumns.id
order by sys.tables.name asc
Advertisement
No trackbacks yet.