Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    18

    Unanswered: Variables Representing Table Names

    Hi, I have googled this topic and I can't find an easy answer so I decided to come here and ask for an explanation on how I can do the following:

    I am trying to declare and set variables = to table names and field names b.c I have a bunch of tables and I have to put unique indexes on fields in each table. I know all the sql to do it and I can replace the table names and field names for each table iteration I need to put the unique index on, but I was hoping I could it using a system table and assigning values to variables that way...but I don't know enough to do that.

    Basically, I have a bunch of fact tables that have a surrogate primary key and another column representing something, i.e., employees, etc. I want to put a unique nonclustered index on each of thies fields (each field is a differnt name with different values from a different table) in about 10 different tables.

    Ideally I would like a way to create a T-SQL statement that I would be able to assign values to variables and just replace maybe one or two lines of the T-SQL statment instead of 10 for each table. What system tables should I use for this? If that is in fact the correct path.

    Thanks for you time.

    Paul

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    You want to put a unique nonclustered index on every column of every table? If not, how do you identify the ones you want this index on? Will it always be one column, or are some of these composite indexes? How many indexes in total?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Aug 2009
    Posts
    18
    15 tables and each table has 1 value field and 1 surrogate primary key field. No composite keys. I only want to put the unique nonclustered index on the 1 value field

    Hope this helps.

    Paul

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    For 15 why don't you copy\ paste and edit? Hardly seems worth automating 15 indexes. 150 granted but 15?
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •