[SQL] DB Design

2008-03-14 Thread PostgreSQL Admin
I have a inventory system design in which I would like some help with to see if it's efficient. The products are broken into: Product tables Property tables Configurable Products - this would include colors (i.e. - black, blue and green) tied to products I'm thinking of breaking inventory in

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
so, after the needed modifications the SQL schema is the following -- SQL schema for business-test-db2 CREATE TABLE customers ( customer_code serial UNIQUE, alfa_customer_code varchar(6), customer_name character varying(250) NOT NULL, address character varying(250) NOT NULL, city chara

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
[cut] Given this table layout, I'm gonna take a wild guess and ask if you're coming from MySQL and expecting the second serial order_code to be a sub-autoincrement to id? no, always used PostgreSQL, but i'm having a deeper approach now, until now i've been using th ORDBMS in a very 'easy' mann

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
[cut] It means what it says. You have defined table orders with a primary key of (id,order_code). This means that the combination of (id,order_code) must be unique. yes, that was my thought, and in that context, i thought it could be correct in order to have uniqueness for creating forei

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
Jaime Casanova wrote: [...unnecesary...] CREATE TABLE orders ( id serial, order_code serial, customer_code integer REFERENCES customers (customer_code) NOT NULL, order_date time without time zone NOT NULL, remote_ip inet NOT NULL, order_time timestamp with time zone NOT NULL, order_t

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
John McCawley wrote: Table orders defines the column order_code as a serial, which simple makes a trigger which gives a new value to the column on insert. Note that there is NO guarantee that ths column will be unique. You can manually update the value to whatever you want. If you wish this

Re: [SQL] DB design and foreign keys

2005-12-14 Thread Gianluca Riccardi
[cut] order_code is not by itself unique --- SERIAL doesn't guarantee that. that was my misunderstanding, i thought (misunderstood) that 'serial' implied 'unique' I'm not sure why you are declaring the primary key of orders as being the combination of *two* serial columns, i thought it

Re: [SQL] DB design and foreign keys

2005-12-13 Thread Scott Marlowe
On Tue, 2005-12-13 at 12:16, Gianluca Riccardi wrote: > hello all, > i'm usign PostgreSQL 7.4.7 in a Debian 3.1 > > following is the SQL schema of my (very)small DB for a (very small)web > business application: > CREATE TABLE orders ( >id serial, >order_code serial, >customer_code i

Re: [SQL] DB design and foreign keys

2005-12-13 Thread Richard Huxton
Gianluca Riccardi wrote: hello all, i'm usign PostgreSQL 7.4.7 in a Debian 3.1 CREATE TABLE orders ( id serial, order_code serial, ... PRIMARY KEY (id, order_code) ); CREATE TABLE order_items ( id serial, order_code integer REFERENCES orders (order_code) NOT NULL, when i try t

Re: [SQL] DB design and foreign keys

2005-12-13 Thread Jaime Casanova
[...unnecesary...] > CREATE TABLE orders ( > id serial, > order_code serial, > customer_code integer REFERENCES customers (customer_code) NOT NULL, > order_date time without time zone NOT NULL, > remote_ip inet NOT NULL, > order_time timestamp with time zone NOT NULL, > order_type va

Re: [SQL] DB design and foreign keys

2005-12-13 Thread Tom Lane
Gianluca Riccardi <[EMAIL PROTECTED]> writes: > CREATE TABLE orders ( >id serial, >order_code serial, >customer_code integer REFERENCES customers (customer_code) NOT NULL, >order_date time without time zone NOT NULL, >remote_ip inet NOT NULL, >order_time timestamp with time

Re: [SQL] DB design and foreign keys

2005-12-13 Thread John McCawley
Table orders defines the column order_code as a serial, which simple makes a trigger which gives a new value to the column on insert. Note that there is NO guarantee that ths column will be unique. You can manually update the value to whatever you want. If you wish this column to be unique,

[SQL] DB design and foreign keys

2005-12-13 Thread Gianluca Riccardi
hello all, i'm usign PostgreSQL 7.4.7 in a Debian 3.1 following is the SQL schema of my (very)small DB for a (very small)web business application: -- SQL schema for business-test-db CREATE TABLE customers ( customer_code serial, alfa_customer_code varchar(6), customer_name character var