Syntax error trying to insert an SQL clause [duplicate] - mysql

This question already has answers here:
1064 error in CREATE TABLE ... TYPE=MYISAM
(5 answers)
Closed 9 years ago.
I'm getting this error:
CREATE TABLE `libro`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`autor_id` INTEGER(11),
`titulo` VARCHAR(255),
`paginas` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
INDEX `libro_FI_1` (`autor_id`),
CONSTRAINT `libro_FK_1`
FOREIGN KEY (`autor_id`)
REFERENCES `autor` (`id`)
)Type=InnoDB
[propel-sql-exec] SQLSTATE[42000]: Syntax error or access violation: 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 'Type=InnoDB' at line 12
Any idea?
Regards
Javi

Shouldn't it be ENGINE=InnoDB?

Use ENGINE instead of Type
CREATE TABLE `libro`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`autor_id` INTEGER(11),
`titulo` VARCHAR(255),
`paginas` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
INDEX `libro_FI_1` (`autor_id`),
CONSTRAINT `libro_FK_1`
FOREIGN KEY (`autor_id`)
REFERENCES `autor` (`id`)
)ENGINE=InnoDB

Related

Erro 1064 mysql erro [duplicate]

This question already has answers here:
MySQL Workbench: Error in query (1064): Syntax error near 'VISIBLE' at line 1
(3 answers)
Closed 3 years ago.
Executing SQL script in server
ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '
CONSTRAINT fk_telefone_usuario
FOREIGN KEY (usuario_id)
REFERENCE' at line 12
SQL Code:
CREATE TABLE IF NOT EXISTS dashboard_jr.telefone (
id INT(11) NOT NULL AUTO_INCREMENT,
ddd INT(2) NOT NULL,
telefone INT(9) NOT NULL,
operadora VARCHAR(45) NOT NULL,
tipo ENUM('f', 'm') NOT NULL,
status ENUM('a', 'i') NOT NULL,
usuario_id INT(11) NOT NULL,
created DATETIME NOT NULL,
modified DATETIME NULL DEFAULT NULL,
PRIMARY KEY (id),
INDEX fk_telefone_usuario_idx (usuario_id ASC) VISIBLE,
CONSTRAINT fk_telefone_usuario
FOREIGN KEY (usuario_id)
REFERENCES dashboard_jr.usuario (id)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
The komma immediately before CONSTRAINT

SQL foreign key error?

DROP TABLE IF EXISTS userRole;
DROP TABLE IF EXISTS account;
CREATE TABLE account (
lionID VARCHAR(50) NOT NULL,
firstName VARCHAR(50) NOT NULL,
hashedpass VARCHAR(255) NOT NULL,
PRIMARY KEY (lionID)
);
CREATE TABLE roles (
roleID INT UNSIGNED AUTO_INCREMENT NOT NULL,
lionID VARCHAR(50) NOT NULL,
administrator BOOLEAN NOT NULL DEFAULT False,
qRole VARCHAR(255) NOT NULL,
PRIMARY KEY (roleID),
FOREIGN KEY (lionID) REFERENCES account(lionID)
);
I am having trouble understanding why I am getting an error.. the foreign key lionID in roles is referencing the primary key lionID in account but it doesn't seem to like it. Any help is greatly appreciated.
ERROR 1064 (42000) at line 76: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FOREIGN KEY lionID REFERENCES account lionID'
)' at line 8
I think the problem is in create statement:
You need to use Syntax:
CONSTRAINT `fk_account`
FOREIGN KEY (lionID) REFERENCES account(lionID)

Mysql new Table

I have some doubt in my table
CREATE TABLE user_roles(
user_role_id int(10) unsigned not null,
user_id int(10) unsigned not null,
authority varchar(45) not null,
PRIMARY KEY(user_role_id),
KEY FK_user_roles (user_id),
CONSTRAINT FK_user_roles FOREING KEY (user_id) REFERENCES users (user_id))
ENGINE=InnoDB DEFAULT CHARSET=utf8;
i get the following error:
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
'FOREING KEY (user_id) REFERENCES users (user_id)) ENGINE=InnoDB DEFAULT CHARSET=' at line 7
Simple mistake
FOREIGN not FOREING

Syntax error when running a MySQL CREATE TABLE statement [duplicate]

This question already has answers here:
1064 error in CREATE TABLE ... TYPE=MYISAM
(5 answers)
Closed 9 years ago.
CREATE TABLE users (
user_id INT(8) NOT NULL AUTO_INCREMENT,
user_name VARCHAR(30) NOT NULL,
user_pass VARCHAR(255) NOT NULL,
user_email VARCHAR(255) NOT NULL,
user_date DATETIME NOT NULL,
user_level INT(8) NOT NULL,
UNIQUE INDEX user_name_unique (user_name),
PRIMARY KEY (user_id)
) TYPE=INNODB;
When running this query on the SQL server, I am getting the following error:
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 'TYPE=INNODB' at line 10
Any help on why this is coming up?
Instead of
TYPE=INNODB
set
Engine=InnoDB
Use ENGINE=InnoDB;
http://dev.mysql.com/doc/refman/5.0/en/using-innodb-tables.html
The manual for CREATE TABLE doesn't include TYPE; it seems to use:
ENGINE = INNODB;
And that is the default engine, so you don't really need to specify it.
Try the following query:
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(8) NOT NULL AUTO_INCREMENT,
`user_name` varchar(30) NOT NULL,
`user_pass` varchar(255) NOT NULL,
`user_email` varchar(255) NOT NULL,
`user_date` datetime NOT NULL,
`user_level` int(8) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_name_unique` (`user_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

MySQL statement syntax

I'm experiencing problems with this MySQL statement:
CREATE TABLE Articoli (Cod_Articolo char(10) NOT NULL,
Des_Articolo varchar(50) NOT NULL,
Cat_Articolo char(2) NOT NULL,
Ubi_Articolo char(6) NOT NULL,
PRIMARY KEY (Cod_Articolo)
FOREIGN KEY (Cat_Articolo) REFERENCES Categorie(Cod_Categoria) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB;
I get this error:
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 'FOREIGN KEY
(Cat_Articolo) REFERENCES Categorie(Cod_Categoria) ON DELETE NO ACTI' at line 6
I don't see why...
Thanks, Mauro
You are missing a comma here:
PRIMARY KEY (Cod_Articolo)
Try this:
CREATE TABLE Articoli (Cod_Articolo char(10) NOT NULL,
Des_Articolo varchar(50) NOT NULL,
Cat_Articolo char(2) NOT NULL,
Ubi_Articolo char(6) NOT NULL,
PRIMARY KEY (Cod_Articolo),
FOREIGN KEY (Cat_Articolo) REFERENCES Categorie(Cod_Categoria) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB;