Thread: constrains questios ..

constrains questios ..

From
Rafal Kedziorski
Date:
Hi,

is better to create constrains while creating table or after the table 
is created? I'm working on sql script which should create about 40 tables.


Best Regards,
Rafal



Re: constrains questios ..

From
Johannes Lochmann
Date:
On Tuesday 11 February 2003 16:35, Rafal Kedziorski wrote:
Hi,

> is better to create constrains while creating table or after the table
> is created? I'm working on sql script which should create about 40 tables.

I usually first create the tables, then the constraints. Rational: You can
create the tables in any sequence you want to.

HTH

Johannes Lochmann

--
Disclaimer - These opiini^H^H damn! ^H^H ^Q ^[ .. :w :q :wq :wq! ^d X^?
exit X Q ^C ^c ^? :quitbye  CtrlAltDel  ~~q :~q logout save/quit :!QUIT
^[zz ^[ZZZZZZ ^H  man vi ^@ ^L ^[c ^# ^E ^X ^I ^T ? help helpquit ^D ^d
man help ^C exit ?Quit ?q CtrlShftDel "Hey, what does this button d..."



Re: constrains questios ..

From
"Matthew Nuzum"
Date:
> > is better to create constrains while creating table or after the
table
> > is created? I'm working on sql script which should create about 40
> tables.
> 
> I usually first create the tables, then the constraints. Rational: You
can
> create the tables in any sequence you want to.
> 
> HTH
> 
> Johannes Lochmann
> 

Can you please demonstrate the syntax you would use to create the
constraints?  I'm not real clear on this and my attempts haven't
produced what I wanted.

--
Matthew Nuzum
www.bearfruit.org
cobalt@bearfruit.org



Re: constrains questios ..

From
Johannes Lochmann
Date:
On Tuesday 11 February 2003 18:41, Matthew Nuzum wrote:
> Can you please demonstrate the syntax you would use to create the
> constraints?  I'm not real clear on this and my attempts haven't
> produced what I wanted.

Checked the docs? They are really good at this point. Anyways.

The following creates Tables A, B and AB. A and B have an id and a text field,
AB connects them (N:M relation).

create table A (id integer not null primary key,something varchar(16)
);

create table B (id integer not null primary key,otherthing varchar(16)
);

create table AB (id_a integer not null,id_b integer not null,
constraint pk_AB primary key(id_a, id_b)
);

create unique index u_A_something on A (something);
create unique index u_A_otherthing on B (otherthing);

alter table AB add constraint fk_AB_A_exists foreign key(id_a) references
A(id);
alter table AB add constraint fk_AB_B_exists foreign key(id_b) references
B(id);

HTH

Johannes Lochmann

--
Disclaimer - These opiini^H^H damn! ^H^H ^Q ^[ .. :w :q :wq :wq! ^d X^?
exit X Q ^C ^c ^? :quitbye  CtrlAltDel  ~~q :~q logout save/quit :!QUIT
^[zz ^[ZZZZZZ ^H  man vi ^@ ^L ^[c ^# ^E ^X ^I ^T ? help helpquit ^D ^d
man help ^C exit ?Quit ?q CtrlShftDel "Hey, what does this button d..."