Creating Index question

  • When you right click, "Script Index as..."Create To...New Window", your query windows is populated with ALTER TABLE [tablename] ADD CONSTRAINT [index name].

    However MSDN has an article on CREATE INDEX [tablename] http://msdn.microsoft.com/en-us/library/ms188783(v=sql.90).aspx

    What is the difference and is any one better than the other? Are Constraints the Same as Indexes?

    SQL Padre
    aka Robert M Bishop

    "Do or do not, there is no try" -- Yoda

  • What you're seeing is most likely the primary key, which is both.

    The Primary Key is a specific type of index that is also a constraint, and is created as such against the table. In this case, it's basically the same thing.

    If you have a particular issue to look at we could help describe the exact differences.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • I can understand your little confusion: in SQL Server Management Studio the PK is listed in the folder "Indexes" and not in "Constraints".

    The reason is, that is is more than "only" a constraint, internally an index is created.

    Every key constraint listed here...:

    select * from sys.key_constraints

    ... has also an entry here:

    select * from sys.indexes

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply