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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.