Generate script of all indexes, keys in the SQL Server database -
i looking generate scripts like:
alter table dbo.person add constraint pk_person primary key clustered (personid); create index ix_evt_events on evt_events(prg_event_t1, prg_event_t2, num_order)
the main problem cannot find information need, example query:
select t.name tablename, i.* sys.indexes inner join sys.tables t on i.object_id=t.object_id
returns information keys , indexes, but.. there no "columns' name" can them?
i tried sys.all_columns , sys.key_constraints also.
column names stored in sys.columns
andsys.index_columns
tables.
this select column names tables:
select sc.name sys.tables st inner join sys.columns sc on sc.object_id = st.object_id st.object_id = 'objectid'
or join sys.indexes
table, select table name , columns:
select st.name , sc.name sys.indexes si inner join sys.tables st on si.object_id = st.object_id inner join sys.columns sc on sc.object_id = st.object_id
you can add where
clause statement filter on index column
select si.name , st.name , sc.name sys.indexes si inner join sys.tables st on si.object_id = st.object_id inner join sys.columns sc on sc.object_id = st.object_id si.name = 'ix_evt_events'
Comments
Post a Comment