Jump to content


Photo

a newbie question


  • Please log in to reply
4 replies to this topic

#1 Dale_H

Dale_H
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 August 2003 - 04:31 PM

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

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 27 August 2003 - 05:08 PM

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.\'


Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Dale_H

Dale_H
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 August 2003 - 08:47 PM

thank you :P

#4 Dale_H

Dale_H
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 August 2003 - 02:18 AM

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

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 30 August 2003 - 04:52 AM

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`) )

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users