0

when i put this in phpmyadmin i get errors... can anyone look over it and find a mistake..

CREATE TABLE Student {

SID int NOT NULL default,
SNAME varchar(200) NOT NULL default,
ADDRESS text NOT NULL default,
POST_CODE varchar(10) NOT NULL default,
PHOTO mediumblob NOT NULL default,

Primary Key (SID)


} ENGINE=INNODB



CREATE TABLE Course {

CID int NOT NULL default,
CNAME varchar(200) NOT NULL default,
DEPARTMENT text NOT NULL default,

Primary Key (CID)

} ENGINE=INNODB


CREATE TABLE Student-Course {
SID int NOT NULL default,
CID int NOT NULL default,
GRADE varchar(200) NOT NULL default,
COMMENTS text NOT NULL default,

Primary Key (SID,CID),
FOREIGN KEY (CID) REFERENCES Course (CID)  ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (SID) REFERENCES Student (SID) ON UPDATE CASCADE ON DELETE CASCADE
} ENGINE=INNODB
4
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by pritaeas
2

Use plain brackets () instead of curly brackets {}
Add a semicolon ; after each statement (after "INNODB")

0
CREATE TABLE Student{SID int( 8 ) NOT NULL AUTO_INCREMENT ,
SNAME varchar( 200 ) NOT NULL default,
ADDRESS text NOT NULL default,
POST_CODE varchar( 10 ) NOT NULL default,
PHOTO mediumblob NOT NULL default,
PRIMARY KEY ( SID ) } ENGINE = INNODB;

for this i get this error

#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 '{ SID int(8) NOT NULL auto_increment, SNAME varchar(200) NOT NULL default, ' at line 1

0

1. Use plain brackets () instead of curly brackets {}
2. Add a semicolon ; after each statement (after "INNODB")

You forgot to change 1.

0

Apart from still using { } instead of ( )
where you have any line like this

SNAME varchar( 200 ) NOT NULL default,

you have to state what the default value is.
eg
SNAME varchar( 200 ) NOT NULL default 'fred',

so obviously you will have trouble setting default values for some fields, like name, address, post_code, in fact ALL the fields where you have used default!

Default is normally used where you can have the database automatically insert a valid default value - say no, which you will occasionally later set to yes . so in a houses for rent database, the default value for a new property for available would be yes, which you'd change to no whenever it was rented out. Your query to display available to rent property on a web site would then use "where available='yes' ", so visitors don't get excited about a property, only to discover it's been rented out for years.

Edited by drjohn: n/a

0

Now THIS is a glider (and it's mine) ;)

Nice. I had the privilige of joining in a two-seater once. Very, very impressive...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.