Jump to content

a newbie question


Dale_H

Recommended Posts

I am teaching my self database and I ran into a snage, my table will not build right.

 

here is my bad code

 

CREATE TABLE `Monitors` (

 

`Type` TEXT( 25 ) NOT NULL ,

`Size` INT( 10 ) NOT NULL ,

`Price` FLOAT( 10 ) NOT NULL ,

`Descripton` LONGTEXT( 60 ) NOT NULL ,

PRIMARY KEY ( `Type` )

) COMMENT = \'The type, size, price, and description of the moniters in stock.\'

 

and here is the error

 

MySQL said:

 

 

You have an error in your SQL syntax near \'(25) NOT NULL, `Size` INT(10) NOT NULL, `Price` FLOAT(10) NOT NULL, `Descripton`\' at line 1

 

 

P.S. This is not a home work or anything, this is just a exsample database :P

 

Any help would be cool :P

Link to comment
https://forums.phpfreaks.com/topic/946-a-newbie-question/
Share on other sites

you cannot specify the lengths for the TEXT and LONGTEXT fields; the exception is your TEXT field needs a length specified because it is the primary key: this length is placed in the primary key line.

 

CREATE TABLE `Monitors` (  

`Type` TEXT NOT NULL,  

`Size` INT(10) NOT NULL,  

`Price` FLOAT(10) NOT NULL,  

`Descripton` LONGTEXT NOT NULL,  

PRIMARY KEY (`Type`(25))  

) COMMENT = \'The type, size, price, and description of the moniters in stock.\'

Link to comment
https://forums.phpfreaks.com/topic/946-a-newbie-question/#findComment-3204
Share on other sites

If `type` is a model number or something like that (which would make more sense as a primary key) then define it as varchar(25). TEXT fields will hold a short novel.

 

CREATE TABLE `Monitors` ( 

`Type` VARCHAR(25) NOT NULL, 

`Size` INT(10) NOT NULL, 

`Price` FLOAT(10) NOT NULL, 

`Descripton` TEXT NOT NULL, 

PRIMARY KEY (`Type`) 

) 

Link to comment
https://forums.phpfreaks.com/topic/946-a-newbie-question/#findComment-3243
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.