REFERENCES troubles

Started by planx plnetxalmost 26 years ago5 messagesgeneral
Jump to latest
#1planx plnetx
planetx2100@hotmail.com

I get this error when creating a database:

CREATE TABLE workers(
name varchar(30),
firstname varchar(30),
id_personal decimal(10)NOT NULL UNIQUE PRIMARY KEY,
);

CREATE TABLE payements(
date_of date,
owner REFERENCES workers(id_personal)
);

IT gimme error!!!
why this isn't right?
the postgres documentation seem say to do in this manner...
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

#2Robert B. Easter
reaster@comptechnews.com
In reply to: planx plnetx (#1)
Re: REFERENCES troubles

On Tue, 04 Jul 2000, planx plnetx wrote:

I get this error when creating a database:

CREATE TABLE workers(
name varchar(30),
firstname varchar(30),
id_personal decimal(10)NOT NULL UNIQUE PRIMARY KEY,
);

CREATE TABLE payements(
date_of date,
owner REFERENCES workers(id_personal)
);

IT gimme error!!!
why this isn't right?
the postgres documentation seem say to do in this manner...

You could try something like this instead:

CREATE TABLE workers(
id_personal SERIAL PRIMARY KEY,
name VARCHAR(30),
firstname VARCHAR(30)
);
CREATE TABLE payements(
date_of DATE,
owner REFERENCES workers
);

PRIMARY KEY implies UNIQUE NOT NULL
SERIAL will be an INTEGER DEFAULT nextval('workers_id_personal_seq') so they
get a number automatically.

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

--
Robert

#3'JanWieck@t-online.de'
JanWieck@t-online.de
In reply to: planx plnetx (#1)
Re: REFERENCES troubles

planx plnetx wrote:

I get this error when creating a database:

CREATE TABLE workers(
name varchar(30),
firstname varchar(30),
id_personal decimal(10)NOT NULL UNIQUE PRIMARY KEY,
);

CREATE TABLE payements(
date_of date,
owner REFERENCES workers(id_personal)
);

IT gimme error!!!
why this isn't right?
the postgres documentation seem say to do in this manner...

First thing incorrect is that you aren't creating a database,
you are creating tables inside of an existing one.

Second you just told us the statements that didn't work, but
not what the database is yelling, nor which version of
Postgres did so or the like.

Forgiven :-)

Third the comma after "PRIMARY KEY" in the "workers" table
declaration is a syntax error.

Forth you forgot to specify the data type of "owner" in the
"payments" table. If I add "decimal(10)" before "REFERENCES"
it works pretty good in 7.0.x.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #

#4planx plnetx
planetx2100@hotmail.com
In reply to: 'JanWieck@t-online.de' (#3)
Re: REFERENCES troubles

From: "Robert B. Easter" <reaster@comptechnews.com>
To: "planx plnetx" <planetx2100@hotmail.com>, pgsql-general@postgresql.org
Subject: Re: [GENERAL] REFERENCES troubles
Date: Tue, 4 Jul 2000 18:38:28 -0400

On Tue, 04 Jul 2000, planx plnetx wrote:

I get this error when creating a database:

CREATE TABLE workers(
name varchar(30),
firstname varchar(30),
id_personal decimal(10)NOT NULL UNIQUE PRIMARY KEY,
);

CREATE TABLE payements(
date_of date,
owner REFERENCES workers(id_personal)
);

IT gimme error!!!
why this isn't right?
the postgres documentation seem say to do in this manner...

You could try something like this instead:

CREATE TABLE workers(
id_personal SERIAL PRIMARY KEY,
name VARCHAR(30),
firstname VARCHAR(30)
);
CREATE TABLE payements(
date_of DATE,
owner REFERENCES workers
);

PRIMARY KEY implies UNIQUE NOT NULL
SERIAL will be an INTEGER DEFAULT nextval('workers_id_personal_seq') so
they
get a number automatically.

Yes thanks, but why I can't specify a column like the manual say:
REFERENCES workers(id_personal)?

how the simple REFERENCES workers can get the primary key? maybe it is
automatiQUE????????
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

#5Jesus Aneiros
aneiros@jagua.cfg.sld.cu
In reply to: planx plnetx (#4)
Re: REFERENCES troubles

Delete the , after KEY and give owner a datatype and everything works
fine. I have tested.

Jesus.

On Wed, 5 Jul 2000, planx plnetx wrote:

Show quoted text

CREATE TABLE workers(
name varchar(30),
firstname varchar(30),
id_personal decimal(10)NOT NULL UNIQUE PRIMARY KEY,
);

CREATE TABLE payements(
date_of date,
owner REFERENCES workers(id_personal)
);