2014-09-20 3 views
0

Je suis en train d'entrer ces données comme un exemple pour apprendre sql mais obtenir cette erreur
#1064 - 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 ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' at line 5
Voici mon code SQL:Débutant @ SQL: requête SQL Erreur

CREATE TABLE IF NOT EXISTS `majors` (
    `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, 
    `price` decimal(10,2) DEFAULT NULL, 
    `about` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL, 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 

INSERT INTO `majors` (`name`, `price`, `about`) VALUES('Applied Physics', 20.00, 'Applied Physics'); 
INSERT INTO `majors` (`name`, `price`, `about`) VALUES('Computer Science', 15.00, 'Computer Science'); 
+0

Vous devez citer '' 20.00' et 15.00' et de supprimer la virgule après la dernière NULL DEFAULT ',' –

+3

@ Fred-ii- - pas besoin de citer des décimales, mais la virgule est l'erreur. – sgeddes

+0

@sgeddes La période ne déclencherait-elle pas une erreur? Je pensais que ça aurait. –

Répondre

2

Supprimer la virgule après DEFAULT NULL:

CREATE TABLE IF NOT EXISTS `majors` (
    `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, 
    `price` decimal(10,2) DEFAULT NULL, 
    `about` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL, <-- remove the comma 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 

http://sqlfiddle.com/#!2/a2694

+0

ahhhh merci beaucoup! – MIT