Error 1064 in create table [closed]

0
  

(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 'UNSIGNED AUTO_INCREMENT, nomCognoms varchar (60) not NULL unique_key, adreca goes' at line 2

$sql = "CREATE TABLE aligxager 
(id INT(11) not NULL UNSIGNED AUTO_INCREMENT, 
nomCognoms varchar(60) not NULL unique_key, 
adreca varchar(50) not NULL, 
ciutat varchar(50) not NULL, 
cp varchar(50) not NULL, 
comarcaPais varchar(50) not NULL, 
dataNaix varchar(20) not NULL, 
adrecaE varchar(255) not NULL, 
periode INT(1) not NULL, 
dataPagament INT(1) not NULL, 
esMembre INT(1) not NULL, 
volBanquet INT(1) not NULL, 
volPlanetari  INT(1) not NULL, 
volcotxePlanetari  INT(1) not NULL, 
TotalPagar INT(11) not NULL, 
tipusAllotjament INT(1) not NULL, 
modePagament INT(1) not NULL, 
comentaris blob, 
anyCongres int (11), 
donaco varchar (10),
PRIMARY KEY (id))";
    
asked by Joan Inglada Roig 25.03.2017 в 12:26
source

3 answers

1

It's a syntax error I think it may be because of this (unique_key):

$sql = "CREATE TABLE aligxager 
(id INT(11) not NULL UNSIGNED AUTO_INCREMENT, 
nomCognoms varchar(60) not NULL unique_key, //Cambialo por UNIQUE
adreca varchar(50) not NULL, 
ciutat varchar(50) not NULL, 
cp varchar(50) not NULL, 
comarcaPais varchar(50) not NULL, 
dataNaix varchar(20) not NULL, 
adrecaE varchar(255) not NULL, 
periode INT(1) not NULL, 
dataPagament INT(1) not NULL, 
esMembre INT(1) not NULL, 
volBanquet INT(1) not NULL, 
volPlanetari  INT(1) not NULL, 
volcotxePlanetari  INT(1) not NULL, 
TotalPagar INT(11) not NULL, 
tipusAllotjament INT(1) not NULL, 
modePagament INT(1) not NULL, 
comentaris blob, 
anyCongres int (11), 
donaco varchar (10),
PRIMARY KEY (id))";

That's how it would look:

nomCognoms varchar(60) not NULL UNIQUE,

and if not, try removing the UNSIGNED as it is auto_increment that sentence is not needed since mysql starts from 1:

(id INT(11) not NULL AUTO_INCREMENT, 
    
answered by 25.03.2017 / 14:53
source
1

THIS WORKS (I have elaborated and tested it on my localhost)

You can do it with 2 queries. First we create the table:

CREATE TABLE aligxager 
('id' int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
nomCognoms varchar(60) not NULL, 
adreca varchar(50) not NULL, 
ciutat varchar(50) not NULL, 
cp varchar(50) not NULL, 
comarcaPais varchar(50) not NULL, 
dataNaix varchar(20) not NULL, 
adrecaE varchar(255) not NULL, 
periode INT(1) not NULL, 
dataPagament INT(1) not NULL, 
esMembre INT(1) not NULL, 
volBanquet INT(1) not NULL, 
volPlanetari  INT(1) not NULL, 
volcotxePlanetari  INT(1) not NULL, 
TotalPagar INT(11) not NULL, 
tipusAllotjament INT(1) not NULL, 
modePagament INT(1) not NULL, 
comentaris blob, 
anyCongres int (11), 
donaco varchar (10),
PRIMARY KEY (id));

And later we added Unique key to the nomCognoms:

ALTER TABLE 'aligxager' ADD UNIQUE ('nomCognoms');

ALL IN ONE:

$sql = "CREATE TABLE aligxager 
('id' int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
nomCognoms varchar(60) not NULL, 
adreca varchar(50) not NULL, 
ciutat varchar(50) not NULL, 
cp varchar(50) not NULL, 
comarcaPais varchar(50) not NULL, 
dataNaix varchar(20) not NULL, 
adrecaE varchar(255) not NULL, 
periode INT(1) not NULL, 
dataPagament INT(1) not NULL, 
esMembre INT(1) not NULL, 
volBanquet INT(1) not NULL, 
volPlanetari  INT(1) not NULL, 
volcotxePlanetari  INT(1) not NULL, 
TotalPagar INT(11) not NULL, 
tipusAllotjament INT(1) not NULL, 
modePagament INT(1) not NULL, 
comentaris blob, 
anyCongres int (11), 
donaco varchar (10),
PRIMARY KEY (id));
ALTER TABLE 'aligxager' ADD UNIQUE ('nomCognoms');
";
    
answered by 25.03.2017 в 15:03
-1

Try this:

$sql = "CREATE TABLE aligxager (
  id int(11) unsigned NOT NULL AUTO_INCREMENT,
  nomCognoms varchar(60) NOT NULL,
  adreca varchar(50) NOT NULL,
  ciutat varchar(50) NOT NULL,
  cp varchar(50) NOT NULL,
  comarcaPais varchar(50) NOT NULL,
  dataNaix varchar(20) NOT NULL,
  adrecaE varchar(255) NOT NULL,
  periode int(1) NOT NULL,
  dataPagament int(1) NOT NULL,
  esMembre int(1) NOT NULL,
  volBanquet int(1) NOT NULL,
  volPlanetari int(1) NOT NULL,
  volcotxePlanetari int(1) NOT NULL,
  TotalPagar int(11) NOT NULL,
  tipusAllotjament int(1) NOT NULL,
  modePagament int(1) NOT NULL,
  comentaris blob,
  anyCongres int(11) DEFAULT NULL,
  donaco varchar(10) DEFAULT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY un_nomCognoms_aligxager (nomCognoms)
)"
    
answered by 25.03.2017 в 12:58