|
Posted by ancelotp on August 5, 2006, 10:37 am
Please log in for more thread options
ancelotp@gmail.com wrote:
> hi
> thanks so much for that man
> i new that code was fishy
>
>
> Bill Karwin wrote:
> > ancelotp@gmail.com wrote:
> > > i totally cant understand the last two lines of code in this create
> > > statement :
> > > UNIQUE uno (uno),
> > > KEY uno_2 (uno)
> >
> > "KEY" is a synonym for "INDEX". It just means that the column `uno` is
> > indexed.
> >
> > "UNIQUE" is a unique constraint; all values in the column must be
> > distinct. This also implies the creation of an index on the `uno` column.
> >
> > It appears in this case that both of these are redundant and
> > unnecessary, since you already have the `uno` column declared as a
> > PRIMARY KEY, which implies both an index and a unique constraint.
> >
> > But in some older versions of MySQL, you had to explicitly create an
> > index on a column before declaring a foreign key constraint on that
> > column. In more recent versions, declaring a FOREIGN KEY does it for you.
> >
> > I don't think it was ever necessary to create an index for a PRIMARY
> > KEY, the declaration of that constraint automatically creates a unique
> > index. But the designer of the database may not have known this.
> >
> > I don't think it hurts anything to have these redundant indexes, but it
> > uses space that you don't need to use, and may have effects on the query
> > optimizer. You should be able to drop the redundant indexes safely:
> >
> > ALTER TABLE DROP INDEX uno, DROP INDEX uno_2;
> >
> > Regards,
> > Bill K.
hi
i still dont get what the uno_2 is
is it the name for the index variable as different from the variable or
is it some sql convention
|