Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes Regarding Database Index Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Regarding Database Index" Watch "Regarding Database Index" New topic

Regarding Database Index

Priyakant Charokar
Ranch Hand

Joined: May 08, 2004
Posts: 58

Does creating a table automatically creates index on the column.
I mean if I will create a table
create table.....(id, name)
Will this automatically be indexed on id and name ?

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

No. Nor should it be. Indices incur a decrease in insert/update/delete performance so you wouldn't want them added by default.

Some database s (such as SQL Server) will automatically create indices on columns that are foreign keys. Other than that by and large its up to you to choose what to index.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31634

Many databases automatically create an index on the primary key (likely id in your example.)

There would be no point in creating an index on all the columns in the table - automatically or manually. The reason is that such an index would be just as large as the source table. Which means it would take just as long to scan as the table.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Priyakant Charokar
Ranch Hand

Joined: May 08, 2004
Posts: 58

Thanks alot for the promt replies
I agree. Here's the link:
subject: Regarding Database Index