to find name of indexes by name of fields

  • I need to change type of many fields.

    It can't be done without drop all constraints and indexes.

    It's not difficulties with constraints.

    How can I build automaticaly sentences  "drop index ...", "create index ..."

    when I know only names of fields to change .

     

    Thanks in advance.

  • select

    object_name(i.id) AS TableName,

    c.name as FieldName,

    I.Name AS IndexName ,

    objectproperty(object_id(i.name),'IsPrimarykey') AS IsPrimaryKey

    from sysindexkeys as ik

    inner join sysindexes as i

    on ik.id = i.id

    and ik.indid = i.indid

    inner join syscolumns as c

    on ik.id = c.id

    and ik.colid=c.colid

    where objectproperty(i.id,'IsUserTable')=1

    AND c.name = @YourFieldName

  • It works great.

    Thank you very much, David.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply