Thread: PRIMARY KEY and UNIQUE

PRIMARY KEY and UNIQUE

From
Erwin Ambrosch
Date:
Hi,

I have a such a table.

CREATE TABLE int_article (
  name          VARCHAR(12) UNIQUE
  headline      TEXT,
  summary      TEXT,
  main            TEXT,
  footer           TEXT,
  PRIMARY KEY (name)
);

Is the UNIQUE constraint neccessary, because if have specified the column
name to be the primary key.

Thanks in advance
Erwin

Re: PRIMARY KEY and UNIQUE

From
Darren Ferguson
Date:
If it is a primary key then it will automatically be UNIQUE.

You do not need the unique next to the VARCHAR in this situation

Darren

On Thu, 14 Feb 2002, Erwin Ambrosch wrote:

> Hi,
>
> I have a such a table.
>
> CREATE TABLE int_article (
>   name          VARCHAR(12) UNIQUE
>   headline      TEXT,
>   summary      TEXT,
>   main            TEXT,
>   footer           TEXT,
>   PRIMARY KEY (name)
> );
>
> Is the UNIQUE constraint neccessary, because if have specified the column
> name to be the primary key.
>
> Thanks in advance
> Erwin
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>


Re: PRIMARY KEY and UNIQUE

From
Andrew Gould
Date:
--- Erwin Ambrosch <ambre@ebutec.com> wrote:
> Hi,
>
> I have a such a table.
>
> CREATE TABLE int_article (
>   name          VARCHAR(12) UNIQUE
>   headline      TEXT,
>   summary      TEXT,
>   main            TEXT,
>   footer           TEXT,
>   PRIMARY KEY (name)
> );
>
> Is the UNIQUE constraint neccessary, because if have
> specified the column
> name to be the primary key.
>
> Thanks in advance
> Erwin

No; but if you eliminate 'UNIQUE', you'll need to
replace it with 'NOT NULL'.

Andrew Gould


__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com

Re: PRIMARY KEY and UNIQUE

From
"Liam DeMasi"
Date:
Andrew,

I thought that just by declaring the field the Primary Key makes it
automatically NOT NULL and UNIQUE?
Am I wrong?

Liam

>-----Original Message-----
>From: pgsql-general-owner@postgresql.org
>[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Andrew Gould
>Sent: Thursday, February 14, 2002 10:31 AM
>To: ambre@ebutec.com; pgsql-general@postgresql.org
>Subject: Re: [GENERAL] PRIMARY KEY and UNIQUE
>
>
>--- Erwin Ambrosch <ambre@ebutec.com> wrote:
>> Hi,
>>
>> I have a such a table.
>>
>> CREATE TABLE int_article (
>>   name          VARCHAR(12) UNIQUE
>>   headline      TEXT,
>>   summary      TEXT,
>>   main            TEXT,
>>   footer           TEXT,
>>   PRIMARY KEY (name)
>> );
>>
>> Is the UNIQUE constraint neccessary, because if have
>> specified the column
>> name to be the primary key.
>>
>> Thanks in advance
>> Erwin
>
>No; but if you eliminate 'UNIQUE', you'll need to
>replace it with 'NOT NULL'.
>
>Andrew Gould
>
>
>__________________________________________________
>Do You Yahoo!?
>Send FREE Valentine eCards with Yahoo! Greetings!
>http://greetings.yahoo.com
>
>---------------------------(end of
>broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to
>majordomo@postgresql.org)
>


Re: PRIMARY KEY and UNIQUE

From
Andrew Gould
Date:
I just tried it; and you are correct.  I must be
confusing my database applications.

Andrew

--- Liam DeMasi <ldemasi@acsinc-nj.com> wrote:
> Andrew,
>
> I thought that just by declaring the field the
> Primary Key makes it
> automatically NOT NULL and UNIQUE?
> Am I wrong?
>
> Liam
>
> >-----Original Message-----
> >From: pgsql-general-owner@postgresql.org
> >[mailto:pgsql-general-owner@postgresql.org]On
> Behalf Of Andrew Gould
> >Sent: Thursday, February 14, 2002 10:31 AM
> >To: ambre@ebutec.com; pgsql-general@postgresql.org
> >Subject: Re: [GENERAL] PRIMARY KEY and UNIQUE
> >
> >
> >--- Erwin Ambrosch <ambre@ebutec.com> wrote:
> >> Hi,
> >>
> >> I have a such a table.
> >>
> >> CREATE TABLE int_article (
> >>   name          VARCHAR(12) UNIQUE
> >>   headline      TEXT,
> >>   summary      TEXT,
> >>   main            TEXT,
> >>   footer           TEXT,
> >>   PRIMARY KEY (name)
> >> );
> >>
> >> Is the UNIQUE constraint neccessary, because if
> have
> >> specified the column
> >> name to be the primary key.
> >>
> >> Thanks in advance
> >> Erwin
> >
> >No; but if you eliminate 'UNIQUE', you'll need to
> >replace it with 'NOT NULL'.
> >
> >Andrew Gould
> >
> >
> >__________________________________________________
> >Do You Yahoo!?
> >Send FREE Valentine eCards with Yahoo! Greetings!
> >http://greetings.yahoo.com
> >
> >---------------------------(end of
> >broadcast)---------------------------
> >TIP 2: you can get off all lists at once with the
> unregister command
> >    (send "unregister YourEmailAddressHere" to
> >majordomo@postgresql.org)
> >
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org


__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com

Re: PRIMARY KEY and UNIQUE

From
Martín Marqués
Date:
On Jue 14 Feb 2002 12:29, Darren Ferguson wrote:
> If it is a primary key then it will automatically be UNIQUE.

Even more, it will create a "INDEX UNIQUE ...." over the primary key field.

Saludos... :-)

--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués                  |        mmarques@unl.edu.ar
Programador, Administrador, DBA |       Centro de Telematica
                       Universidad Nacional
                            del Litoral
-----------------------------------------------------------------

Re: PRIMARY KEY and UNIQUE

From
Martín Marqués
Date:
On Vie 15 Feb 2002 08:42, Martín Marqués wrote:
> On Jue 14 Feb 2002 12:29, Darren Ferguson wrote:
> > If it is a primary key then it will automatically be UNIQUE.
>
> Even more, it will create a "INDEX UNIQUE ...." over the primary key field.

Sorry, I confussed PRIMARY KEY with SERIAL data type.
Ignore that about the INDEX.

Saludos... ;-)

--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués                  |        mmarques@unl.edu.ar
Programador, Administrador, DBA |       Centro de Telematica
                       Universidad Nacional
                            del Litoral
-----------------------------------------------------------------