3

I have a homework assignment and am trying to find my error. I am creating a table in MySQL and am a beginner to this. Please give suggestions!!

Create table computer_inventory 
( 
   assetnumber int(10) not null default “0”,
   manufacturer varchar(15) not null default ‘ ‘, 
   originalcost decimal(12,2) not null default “0”, 
   currentvalue decimal(12,2) not null default ‘0’, 
   boughtfrom varchar(20) not null default ‘ ‘, 
   instock tinyint(1) not null default ‘ ‘, 
   currentuser varchar(20) not null default ‘ ‘, 
   userphonenum varchar(13) not null default ‘ ‘, 
   boughtdate datatime not null default ‘ ‘ 
);

Again, I am new so there may be many errors.

**EDIT:** 

Create table computer_inventory ( 
      assetnumber int(10) not null default 0,
     manufacturer varchar(15) not null default ‘ ‘, 
     originalcost decimal(12,2) not null default 0, 
     currentvalue decimal(12,2) not null default 0, 
     boughtfrom varchar(20) not null default ‘ ‘, 
     instock tinyint(1) not null default 0, 
     currentuser varchar(20) not null default ‘ ‘,
     userphonenum varchar(13) not null default ‘ ‘,
     boughtdate datetime not null default ‘0000-00=00’ 
 );

I am using MySQL 5.6. The error says "Error 1064 (42000): 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 ‘ ‘ ‘, originalcost decimal(12,2) not null default 0, currentvalue decimal(1’ at line 2 "

3
  • 2
    What specifically is the error? Commented Nov 10, 2013 at 1:41
  • what is the whole error? Commented Nov 10, 2013 at 1:43
  • Yes, those are real quotes. The error says "Error 1064 (42000) You have an error in your syntax, check manual.. around line 1. I am assuming I am just missing something or the defaults are wrong.. I have no idea. Commented Nov 10, 2013 at 1:48

1 Answer 1

1

There were a few things wrong... datetime was misspelled. Some of the default values were the wrong datatype for the column, too.

Create table computer_inventory 
( 
   assetnumber int(10) not null default 0,
   manufacturer varchar(15) not null default '', 
   originalcost decimal(12,2) not null default 0, 
   currentvalue decimal(12,2) not null default 0, 
   boughtfrom varchar(20) not null default '', 
   instock tinyint(1) not null default 0, 
   currentuser varchar(20) not null default '', 
   userphonenum varchar(13) not null default '', 
   boughtdate datetime not null  default '0000-00-00'
);

Next time you have this kind of problem, here is what you can do: try making the table with just one or two columns first, if those lines don't have errors, drop the table and re-create it with a few more columns. If you get errors, this will make it easier to isolate exactly what part is incorrect. When I was testing this, I got errors about the wrong default values and stuff like that.... such as instock tinyint(1) not null default ' ', which doesn't work because you're trying to set an empty string to a integer column. It doesn't work. For the datetime default value, I had to look it up on google to see what the appropriate empty date value was. Some of it was trial and error, too, like removing the backticks and replacing them with normal quotes.

EDIT: This works for me without errors... I am testing it with sql fiddle and it is set for MySQL 5.5.31. Tell me the exact error you're getting (we can't help you unless you tell us what the error says, it's impossible for me to guess) and what DB you're using and its version.


This is based on your edit above. You typed 0000-00-00' as 0000-00=00' and you need to use a normal single quote instead of a backtick (I think?).

Create table computer_inventory ( 
     assetnumber int(10) not null default 0,
     manufacturer varchar(15) not null default ' ', 
     originalcost decimal(12,2) not null default 0, 
     currentvalue decimal(12,2) not null default 0, 
     boughtfrom varchar(20) not null default ' ', 
     instock tinyint(1) not null default 0, 
     currentuser varchar(20) not null default ' ',
     userphonenum varchar(13) not null default ' ',
     boughtdate datetime not null default '0000-00-00'
 );
Sign up to request clarification or add additional context in comments.

5 Comments

Okay that helped! It still says I have a syntax error around originalcost and current value.
I am using MySQL 5.6. The error says "Error 1064 (42000): 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 ‘ ‘ ‘, ordiginalcost decimal(12,2) not null default 0, currentvalue decimal(1’ at line 2 "
I am not getting any errors for this. Can you take a look at this link?. Can you update your question with the new statement you are using?
Yeah, I see your link. Not sure why I keep getting the error. I updated the question. Added the error word by word and the updated statement i am entering in.
updated my answer... you need to just copy and paste the code over exactly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.