How does data indexing work in MS SQL?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Newb Mac
    New Member
    • Dec 2010
    • 5

    How does data indexing work in MS SQL?

    I am newbie in MS SQL. Can anyone show me how indexing works in a database??
  • gpl
    New Member
    • Jul 2007
    • 152

    #2
    What do you mean by 'how it works' - what data structures it uses to store the keys ? or how to use indexes ... and where?

    Comment

    • Newb Mac
      New Member
      • Dec 2010
      • 5

      #3
      I mean how to use index in a table..

      Comment

      • gpl
        New Member
        • Jul 2007
        • 152

        #4
        Very simply, use this (but read the relevant articles in Books Online)
        CREATE UNIQUE INDEX name_of_index ON dbo.table_name (column_name_1, column_name_2 .... etc)

        Primary keys are also indexes and are often CLUSTERED - this means the rows are stored in the order the index specifies, and ordinary index keeps a 'table' of the key values and points to the actual rows.

        Note that if you do not pick your primary key carefully and have lots of insertions in different parts of the table, then there will have to be a lot of shuffling of data, causing a big performance drop; if you always add data to the end (using an incrementing integer for example) then this will not be a problem

        Hope this helps

        Comment

        • Newb Mac
          New Member
          • Dec 2010
          • 5

          #5
          indeed it helps..Thanks.. .^^

          Comment

          Working...