Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: Index

  1. #1
    Join Date
    May 2003
    Posts
    70

    Unanswered: Index

    Hi,

    How can I create an Index with Primary in a MSDE database using ADO?
    I used the With Primary clause but I keep receiving invalid syntax near Primary error.

    Create Unique Index PrimaryKey On Activities(Activity_ID) WITH Primary Key;

    What's the problem?

    Should I be using Alter Table Add Constraint?

    Which method is better?

    Thanks,

  2. #2
    Join Date
    Nov 2003
    Posts
    94
    ALTER TABLE [Activities]
    ADD CONSTRAINT PK_Activities
    PRIMARY KEY CLUSTERED
    ([Activity_ID])

  3. #3
    Join Date
    May 2003
    Posts
    70
    Thanks. What's wrong with this statement then?

    Alter Table Audit ADD Constraint Contact_ID (Contact_ID)

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    What error is returned ?

  5. #5
    Join Date
    May 2003
    Posts
    26
    Alter Table Audit ADD Constraint Contact_ID (Contact_ID)
    What kind of constraint are you trying to add?

  6. #6
    Join Date
    May 2003
    Posts
    70
    Invalid Syntax near '('

  7. #7
    Join Date
    Feb 2002
    Posts
    2,232
    Which reference are you using for ado ?

  8. #8
    Join Date
    May 2003
    Posts
    70
    I'm trying to add an index.

    Which one should I use Create INdex or Alter table?

    I can't seem to create a primary key index with Create Index as I keep getting Invalid syntax near Primary error.

  9. #9
    Join Date
    Feb 2002
    Posts
    2,232
    Post your code snippet.

  10. #10
    Join Date
    Feb 2002
    Posts
    2,232
    What language are you using to program with ado ?

  11. #11
    Join Date
    May 2003
    Posts
    70
    I'm using VB. The line that is causing the error is in the posts above.

  12. #12
    Join Date
    Feb 2002
    Posts
    2,232
    Which reference are you using for your ado reference ? Microsoft ActiveX Data Ojbects 2.X library or MS ADO Ext. 2.X for DDL and Security ?

  13. #13
    Join Date
    May 2003
    Posts
    70
    Microsoft ActiveX Data Ojbects 2.X library

  14. #14
    Join Date
    May 2003
    Posts
    70
    Also, What should you use?

    Alter Table Add constraint

    or

    Create Index


    to create indexes?

    does it matter?

  15. #15
    Join Date
    May 2003
    Posts
    26
    Alter Table Audit ADD Constraint Contact_ID (Contact_ID)
    The syntax error is being caused by not identifying the type of constraint, between the constraint name and column name. Also, it would be a good idea to give the constraint a unique name, as in HanafiH's example above.

    ALTER TABLE Audit ADD CONSTRAINT PK_Contact_ID PRIMARY KEY CLUSTERED (Contact_ID)

    Also, make sure the column does not allow NULLs.

Posting Permissions

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