I have a table patient and i have to relate the table patient and table press and doctor .I am using apache2triad and this error display when i try to create table pres
CREATE TABLE `pres` (
`pres_id` SMALLINT(5) NOT NULL AUTO_INCREMENT,
`issuedate` VARCHAR(50) NOT NULL,
`prescriber` VARCHAR(50) NOT NULL,
`sickness` VARCHAR(50) NOT NULL,
`drugname` VARCHAR(50) NOT NULL,
`dose` VARCHAR(50) NOT NULL,
`dosageform` VARCHAR(50) NOT NULL,
`dosageamount` VARCHAR(50) NOT NULL,
`directionofuse` VARCHAR(50) NOT NULL,
`refillinstruction` VARCHAR(50) NOT NULL,
`anycomment` VARCHAR(50) NOT NULL,
PRIMARY KEY (`pres_id`),FOREIGN KEY ('pat_id') REFERENCES patient, FOREIGN KEY('doct1_id') REFERENCES doctor
)
TYPE = myisam;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''Pat_id'),FOREIGN KEY ('Pat_id') REFERENCES patient(id)
ON DEL
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
There's a couple problems here.
1. The CREATE_TABLE statement isn't complete. You aren't defining `pat_id` as one of the fields in your new table. Along with that, the FOREIGN KEY ... REFERENCES syntax should have the table name and the referenced field from that table right after the referenced table name. Like this...
FOREIGN KEY (`pat_id`) REFERENCES patient (`pat_id`),
For consistency, note the backticks also and not single quotes. Also, make sure that the index field in your new table has the same properties as the referenced field.
2. This FOREIGN KEY ... REFERENCES syntax is used for creating foreign key constraints. You are giving the table an engine type of MyIsam. The MyIsam engine does not support foreign key constraints. You must give it another Engine type that supports this like InnoDB. Foreign key constraints are not required to set up relational tables. You can handle things in your program if you want.
http://dev.mysql.com/doc/refman/4.1/en/create-tabl...
--
Alex
lots of blunders right here!... $link = mysql_connect(localhost,$username,$pas..... // shop the decrease back link to close the db later! mysql_select_db($database) or die( "no longer able to decide on database"); // eliminate the @ $question = "insert into `test1` (`html` , `votes` , `value`) values ('yootube123','5','10')"; // observe the variations into punctuation and decrease cases. i anticipate your table is spoke of as and spelt test1 // Use ` (returned single quote) around fields in table and table call, widely used single quote around values. mysql_query($question); // no desire for effect: you basically place a query // upload right here: if (mysql_error()) return ("blunders putting: " . mysql_error() ); // $num=mysql_numrows($effect); // ineffective: $num will incorporate "a million" // $i=0; // on an identical time as ($i < $num) { // $value=mysql_result($effect,$i,"value"); // echo "$value"; // $i++; // incorrect attitude! Now examine all entries: $sq. = "decide on * from `test1` the place a million "; $checklist = mysql_query($sq.); on an identical time as ($lst = mysql_fetch_array($checklist)) echo ($lst[html'] . ", " . $lst['votes'] . ", " .$lst['value'] . "< b r / >"); mysql_free_result($checklist); mysql_close($link);
There are too many problems. May be you need to contact an expert. Check http://k.aplis.net/