hi,
here i was trying to create table with primary key and foreign key.
i had used follwing codings...but getting error like" Can't create table 'test.book' (errno: 150)"..thanku 4 any help
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><title>Create Table</title></head>
<body>
<?
/* Change next two lines */
$db="test";
$link = mysql_connect("localhost");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Select DB Error: ".mysql_error());
/* create table */
mysql_query(
"CREATE TABLE book(
bookid SMALLINT(10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY(bookid),
author VARCHAR(30),
title VARCHAR(30),
accessno INT(20),edition INT(20),publisher VARCHAR(30),
copies INT(10),
status VARCHAR(30),CONSTRAINT fkbook FOREIGN KEY (status)
REFERENCES issue(status))") or die(mysql_error());
mysql_query(
"CREATE TABLE issue(
bookid SMALLINT(10),
author VARCHAR(30),title VARCHAR(30),
accessno INT(20),name VARCHAR(20),regno VARCHAR(30),
date DATE,rdate DATE NOT NULL,
status VARCHAR(30) NOT NULL,CONSTRAINT pkissue PRIMARY KEY (rdate,status))") or die(mysql_error());