Results 1 to 3 of 3

Thread: INSERT INTO SELECT with INDEX

  1. #1
    Join Date
    Apr 2006
    Posts
    178

    INSERT INTO SELECT with INDEX

    for MS SQL 2000

    the following will work if I want to have UNIQUE Users.Name >>
    INSERT INTO [Users] (Name)
    SELECT Names FROM OtherUsers
    where OtherUsers.Names not in (select Name from Users)


    but if I have an UNIQUE INDEX on Users
    CREATE UNIQUE INDEX [IX_Users] ON [Users] ([Name],[Category]) ON [PRIMARY]
    how can I do it ?

    INSERT INTO [Users] (Name, Category)
    SELECT Names,Categories FROM OtherUsers
    where OtherUsers.Names + OtherUsers.Categories not in (select Name, Category from Users)
    ?

    how can I insert it wih an index on 2 or 3 columns ?

    thank you for helping

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Try this one:

    INSERT INTO [Users] (Name, Category)
    SELECT distinct Names, Categories FROM OtherUsers

  3. #3
    Join Date
    Apr 2006
    Posts
    178
    thank you rmiao

Posting Permissions

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