I am newbie in MS SQL. Can anyone show me how indexing works in a database??
How does data indexing work in MS SQL?
Collapse
X
-
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 helpsComment
Comment