Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004

    Unanswered: Make table query that adds a Primary Key

    Hi everyone. I have a make table query that gets its info from other tables that are updated daily. I want to have a button on the switchboard that update my table with the new info. The only problem is I can seem to figure out how to make it add a primary key to a field that exsists already. Some one had this same post a while ago but I couldn't find it with a search.

  2. #2
    Join Date
    Jun 2004
    Florida, US
    I don't know how to do that. but instead make table query, you can do that in 2 steps; you can delete records in the table then insert new records. so primary key numbers will be created by the insert query. not an elegant method but can be the last resort.

  3. #3
    Join Date
    Sep 2003
    The extremely Royal borough of Kensington, London
    1) Create Table

    Select * Into newTable from OldTable [where 1 = 0]

    2) Add Primary Key

    Alter table tableA
    add primary key (id)

    3) Insert from old table(s)

    select * Into new table
    from oldTable ot
    where NOT EXISTS
    (Select null
    from newTable nt
    where nt.key = ot.key)
    Last edited by r123456; 06-11-04 at 22:16.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

Posting Permissions

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