-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: do we need index and constraint in the same time?
PostPosted: Sat Feb 20, 2010 3:30 am 
Newbie

Joined: Mon Jul 21, 2008 5:40 am
Posts: 16
Hi,

codes generated by Ant's hibernate tools usually have a index and a constraint like:

create table info (
id bigint not null auto_increment,
user_id bigint,
primary key (id)
);

alter table info
add index FKAF65AAF96670A934 (user_id),
add constraint FKAF65AAF96670A934
foreign key (user_id)
references user (id);

why there is an index? can it be simply :

alter table info
add constraint FKAF65AAF96670A934
foreign key (user_id)
references user (id);


Top
 Profile  
 
 Post subject: Re: do we need index and constraint in the same time?
PostPosted: Sun Feb 21, 2010 1:25 pm 
Newbie

Joined: Sun Feb 14, 2010 8:08 am
Posts: 12
Indexes allow to find the data in database fast. Adding indexes improves retrieval of data but its optional. so its upon you if u want to use it or not.

PS: For more on index http://en.wikipedia.org/wiki/Index_(database)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.