pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Stupid Question
3+ messages / 3 participants
[nested] [flat]

* Stupid Question
@ 2001-10-02 09:55  Rebekah Kirk <rebekah.kirk@patersons.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Rebekah Kirk @ 2001-10-02 09:55 UTC (permalink / raw)
  To: pgsql-sql

I want to create a table and for whatever reason it will not accept the
command, can anyone say what is wrong as I am very new to Postgres, thanks:

CREATE TABLE cmpnycontacts (
ContactNo integer(10) NOT NULL SERIAL,
CmpnyNo varchar(6) NOT NULL,
FirstName varchar(30) NOT NULL,
Surname varchar(30) NOT NULL,
Phone varchar(20) NOT NULL,
Mobile varchar(20) NOT NULL,
Email varchar(40) NOT NULL,
Country char(2) NOT NULL,
CONSTRAINT cmpnycontacts_pkey PRIMARY KEY (ContactNo)
);






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Stupid Question
@ 2001-10-02 10:30  Nils Zonneveld <nils@mbit.nl>
  parent: Rebekah Kirk <rebekah.kirk@patersons.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Nils Zonneveld @ 2001-10-02 10:30 UTC (permalink / raw)
  To: pgsql-sql



Rebekah Kirk wrote:
> 
> I want to create a table and for whatever reason it will not accept the
> command, can anyone say what is wrong as I am very new to Postgres, thanks:
> 


> CREATE TABLE cmpnycontacts (
> ContactNo integer(10) NOT NULL SERIAL,
> CmpnyNo varchar(6) NOT NULL,
> FirstName varchar(30) NOT NULL,
> Surname varchar(30) NOT NULL,
> Phone varchar(20) NOT NULL,
> Mobile varchar(20) NOT NULL,
> Email varchar(40) NOT NULL,
> Country char(2) NOT NULL,
> CONSTRAINT cmpnycontacts_pkey PRIMARY KEY (ContactNo)
> );


Your problem is with the ContactNo, two things:
- there is no specified length for 'integer', so integer(10) would fail
(integer is defined IIRC as int4, meaning an integer that uses four
bytes to store its values).
- the SERIAL keyword defines a integer coupled to a sequence. 

The following statement would work:

CREATE TABLE cmpnycontacts (
ContactNo SERIAL primary key,
CmpnyNo varchar(6) NOT NULL,
FirstName varchar(30) NOT NULL,
Surname varchar(30) NOT NULL,
Phone varchar(20) NOT NULL,
Mobile varchar(20) NOT NULL,
Email varchar(40) NOT NULL,
Country char(2) NOT NULL
);

Its looks like this table has a relationship to a table that holds the
company data. Since PostgreSQL supports referential integrity you could
extend CmpnyNo in the following way:

CmpnyNo varchar(6) not null references Company 
                            on update cascade 
                            on delete cascade,


Hope this helps,

Nils Zonneveld

-- 
Alles van waarde is weerloos
Lucebert



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Stupid Question
@ 2001-10-02 15:40  Devrim GUNDUZ <devrim@oper.metu.edu.tr>
  parent: Rebekah Kirk <rebekah.kirk@patersons.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Devrim GUNDUZ @ 2001-10-02 15:40 UTC (permalink / raw)
  To: pgsql-sql

<<< No Message Collected >>>



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-10-02 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-10-02 09:55 Stupid Question Rebekah Kirk <rebekah.kirk@patersons.net>
2001-10-02 10:30 ` Nils Zonneveld <nils@mbit.nl>
2001-10-02 15:40 ` Devrim GUNDUZ <devrim@oper.metu.edu.tr>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox