In mySQL, it does nothing. Constraints are not implemented. The syntax is
there for compatibility with other dialects of SQL.
You are almost correct, if constraints were implemented then it would be:
CONSTRAINT fk_authorsofdoc FOREIGN KEY(authorid)
(I think, I don't often write them by hand, that's what data modeling
programs are for!) :)
This would create a foreign key constraint on named fk_authorsofdoc, on
authorid. Basically, that means that whatever value you put in authorid,
has to exist as a primary key value in the table where authorid is the
primary key. (In this case, most likely, the author table) This enforces
referential integrity.
In most dialects of SQL you could set the relationship between authorsofdoc
and authors so that you could not delete a row from authors that had related
records in authorsofdoc. This keeps you from having orphaned records in
authorsofdocs.
The down side is that RI is expensive, processor wise and if you have a busy
database you sometimes end up ripping it out anyhow and enforcing it
manually.
HTH,
Cal
http://www.calevans.com
-----Original Message-----
From: Duke [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 19, 2001 4:16 AM
To: Cal Evans; [EMAIL PROTECTED]
Subject: Re: [RE: What is CONSTRAINTS for?]
Okie...I have this book on Proffessional PHP PRogramming and in the section
of
PHP & SQL Databases they have given this eg. with the CONSTRAINTS
option....it
goes like this.
CREATE TABLE authorsofdoc (
docid INTEGER UNSIGNED NOT NULL,
authorid INTEGER UNSIGNED NOT NULL,
constraint pk_authorsofdoc PRIMARY KEY(docid, authorid)
)
Now what the heck does the 4th line do? i have never seen a syntax like that
in the CREATE TABLE syntax...wats all that 'constraint pk_authorsofdoc' and
after that 'PRIMARY KEY()' option....
infact acording to CREATE TABLE syntax it should be...
CONSTRAINT fk_authorsofdoc FOREIGN KEY(docid, authorid)
isnt it??? or am i wrong?
duke.
"Cal Evans" <[EMAIL PROTECTED]> wrote:
It's not implemented in MySQL. It's there for compatibility.
In other flavors of SQL, constraints can be placed on relationships to
enforce referential integrity.
Cal
http://www.calevans.com
-----Original Message-----
From: Duke [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 19, 2001 3:36 AM
To: [EMAIL PROTECTED]
Subject: What is CONSTRAINTS for?
In the CREATE TABLE command there is a create_defn. option called ...
CONSTRAINT symbol
what is that for?
and how does that work?
duke.
Website: http://www.ilug-bom.org.in/
Ftp site: ftp.ilug-bom.org.in
Chat: irc.ilug-bom.org.in
Linuxers mailing list: [EMAIL PROTECTED]
http://ilug-bom.org.in/mailman/listinfo/linuxers
____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Website: http://www.ilug-bom.org.in/
Ftp site: ftp.ilug-bom.org.in
Chat: irc.ilug-bom.org.in
Linuxers mailing list: [EMAIL PROTECTED]
http://ilug-bom.org.in/mailman/listinfo/linuxers
____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php