Saturday, 14 September 2013

Trying to understand foreign key syntax

Trying to understand foreign key syntax

Just starting out with SQL. I understand the idea of foreign keys just
fine, but I'm trying to learn the syntax of how to implement them and
reading the sqlite page just gives me more questions than answers. Is
there any difference in the following two lines?
CREATE TABLE child(x REFERENCES parent(id));
CREATE TABLE child(FOREIGN KEY x REFERENCES parent(id));
Also, from my understanding, columns are specified by the "table.column"
format, so I'd want to type "parent.id" above, but it seems all the
reading I've done says "parent(id)". What's the difference between the two
and why use parent.id sometimes and parent(id) others?
Are we not supposed to bind any kind of affinity (I think I'm using the
terminology correctly) to the foreign keys because it should just use
whatever the parent key uses?
I have more questions, but this is a good start. Thanks in advance for any
help!

No comments:

Post a Comment