Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    266

    Unanswered: 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
    Feb 2003
    Location
    India
    Posts
    216
    INSERT INTO [Users] (Name, Category)
    SELECT Names,Categories FROM OtherUsers
    where not exists (select Name from Users where Users.Name=OtherUsers.Names and Users.Categories=OtherUsers.Categories)

Posting Permissions

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