Jump to content

Archived

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

Dale_H

a newbie question

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

Share this post


Link to post
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.\'

Share this post


Link to post
Share on other sites

I am using PHP My Admin, how do you add the number to the key if posable?

Share this post


Link to post
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`) 

) 

Share this post


Link to post
Share on other sites

×

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.