Thread: REFERENCES troubles
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
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
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 #
>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
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: > > > 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) > > > );