Foreign key

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dwsddas
Forum Newbie
Posts: 8
Joined: Tue Dec 22, 2009 4:44 am

Foreign key

Post by dwsddas »

Hi, I have a code to create two tables. And the code does not work. Can you tell me where is wrong. I think that I need to do something with INDEX.

Code: Select all

 
 
mysql_query("CREATE TABLE users 
                    (username varchar(15),
                                PRIMARY KEY (username),
                    lastname text,
                    firstname text,
                    password text)
                    ENGINE=INNODB;
                    ")
 
                    mysql_query("CREATE TABLE textt 
                    (username varchar(15), 
                    textname text,
                    textbody text,
                    INDEX (username),
                    FOREIGN KEY (username) REFERENCES users(username))
                            ENGINE=INNODB;
                    ")
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Foreign key

Post by VladSun »

Try
[sql]INDEX IX_username (username)[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
dwsddas
Forum Newbie
Posts: 8
Joined: Tue Dec 22, 2009 4:44 am

Re: Foreign key

Post by dwsddas »

Doesn't work. It shows error message:

Parse error: syntax error, unexpected T_STRING in /home/...
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Foreign key

Post by Weirdan »

You missed semicolons after mysql_query() function calls. It has nothing to do with index or database.
Post Reply