my sql syntax error - mysql

I exported a DB using dbForge (v6) and the whole script has a problem with this:
USE `global-cms-content2`;
CREATE TABLE `global-cms-content2`.umbracorelationtype (
ID int(11) NOT NULL AUTO_INCREMENT,
DUAL bit(1) NOT NULL,
PARENTOBJECTTYPE char(36) NOT NULL,
CHILDOBJECTTYPE char(36) NOT NULL,
NAME varchar(255) NOT NULL,
ALIAS varchar(100) DEFAULT NULL,
PRIMARY KEY (ID)
)
ENGINE = INNODB
AUTO_INCREMENT = 2
AVG_ROW_LENGTH = 16384
CHARACTER SET utf8
COLLATE utf8_general_ci;
Error is :
1 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 'DUAL bit(1) NOT NULL,
PARENTOBJECTTYPE char(36) NOT NULL,
CHILDOBJECTTYPE ' at line 3 SQL2.sql 2 1
Same error happens even when I create the table manually using the editor.
Why is MySQL not working with its own scripts?
Any ideas?
UPDATE:
This did it!
USE `global-cms-content3`;
CREATE TABLE `global-cms-content3`.umbracorelationtype (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`DUAL` bit(1) NOT NULL,
`PARENTOBJECTTYPE` char(36) NOT NULL,
`CHILDOBJECTTYPE` char(36) NOT NULL,
`NAME` varchar(255) NOT NULL,
`ALIAS` varchar(100) DEFAULT NULL,
PRIMARY KEY (ID)
)
ENGINE = INNODB
AUTO_INCREMENT = 2
AVG_ROW_LENGTH = 16384
CHARACTER SET utf8
COLLATE utf8_general_ci;
Still not sure why the export script or the backup DB script doesn't take care of reserved keywords... anyway

The word DUAL is a keyword. See Keyword list.
Try to quote the word as below:
CREATE TABLE `global-cms-content2`.umbracorelationtype (
ID int(11) NOT NULL AUTO_INCREMENT,
`DUAL` bit(1) NOT NULL,
PARENTOBJECTTYPE char(36) NOT NULL,
CHILDOBJECTTYPE char(36) NOT NULL,
NAME varchar(255) NOT NULL,
ALIAS varchar(100) DEFAULT NULL,
PRIMARY KEY (ID)
)

Related

MySQL query for login form not working in phpmyadmin sql query runner

CREATE TABLE `users`(
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(75) NOT NULL, `password` VARCHAR(255) NOT NULL,
`email` VARCHAR(100) NOT NULL,
PRIMARY KEY `id`
UNIQUE KEY `email` (`email`)
)ENGINE = INNODB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci AUTO_INCREMENT = 1;
That's my code for the query I'm trying to run in the phpmyadmin sql query runner to create a table for my users. When I try running the code I get the following 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 'UNIQUE KEY `email` (`email`)
)ENGINE = INNODB DEFAULT CHARSET = utf8 COLLATE...' at line 7
Can someone please help me fix the syntax.
here is the right syntax:
missing comma after pk , missing parentheses defining PK, and wrong syntax for unique key
CREATE TABLE `users`(
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(75) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`email` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`) ,
UNIQUE KEY (`email`)
)ENGINE = INNODB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci AUTO_INCREMENT = 1;
The above answer works but I did:
'''
CREATE TABLE users(
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(75) NOT NULL,
password VARCHAR(255) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE KEY,
)ENGINE = INNODB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci AUTO_INCREMENT = 1;
'''
and it works as well, you can choose whichever. Thanks for the response eshirvana!

How to fix syntax error mysqli 1064 error

ım working localhost, after my work end. I want a upload my db server phpmyadmin. But still syntax error how can ı fix this?
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 '(6) NULL DEFAULT NULL,
PRIMARY KEY (id) USING BTREE
) ENGINE = InnoDB AUTO' at line 7 )
DROP TABLE IF EXISTS `veriler`;
CREATE TABLE `veriler` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`kullanici` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`gpa` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`durumu` int(10) NULL DEFAULT NULL,
`miktari` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`tarih` datetime(6) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
Support for fractional seconds in DATETIME values wasn't added until version MySQL 5.6. If you can't upgrade your server, you will need to remove the trailing (6) from the definition of column tarih i.e.
`tarih` datetime NULL DEFAULT NULL,
Note that you will lose precision in those values relative to your MariaDB server. If you need to store microseconds in your data values, you will need to upgrade the MySQL server to version 5.6 or later.
Try this simplified version:
CREATE TABLE `veriler` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`kullanici` varchar(60) DEFAULT NULL,
`gpa` varchar(255) DEFAULT NULL,
`durumu` int(10) DEFAULT NULL,
`miktari` varchar(20) DEFAULT NULL,
`tarih` datetime(6) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;

MySQL Workbench Error 1064 when creating table

I am trying to use MySQL Workbench 8.0.3 with MariaDB but I get the following error:
Executing:
CREATE TABLE `mydb`.`customer` (
`ID` INT UNIQUE UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL,
`Email` VARCHAR(255) CHARACTER SET 'utf8' NOT NULL,
`Street` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
`City` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
PRIMARY KEY (`ID`));
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 'UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL,
`Email` VARC' at line 2
SQL Statement:
CREATE TABLE `mydb`.`customer` (
`ID` INT UNIQUE UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL,
`Email` VARCHAR(255) CHARACTER SET 'utf8' NOT NULL,
`Street` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
`City` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
PRIMARY KEY (`ID`))
Operation failed: There was an error while applying the SQL script to the database.
The code you see above has been generated using the "Create Table" Workbench feature.
UNSIGNED and INT go together, so this works:
`ID` INT UNSIGNED UNIQUE NOT NULL AUTO_INCREMENT,
This is shorter:
`ID` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
A primary key is already non-NULL and unique. There is no need to declare those properties twice.
I solved it by using int(10) instead of int
ID INT(10)
not
ID INT

Mysql i get Error when i try to edit after insert data

this is my one of database table structure and after insert some fields as row into that i can't update columns and i get error:
CREATE TABLE `channels` (
`id` int(11) NOT NULL,
`channelName` varchar(30) COLLATE utf8_persian_ci NOT NULL,
`channelLink` varchar(50) COLLATE utf8_persian_ci NOT NULL,
`channelDescription` varchar(100) COLLATE utf8_persian_ci NOT NULL,
`channelImageFileName` varchar(100) COLLATE utf8_persian_ci NOT NULL,
`channelAvatarFileName` varchar(100) COLLATE utf8_persian_ci NOT NULL,
`channelState` tinyint(1) NOT NULL,
`channelType` enum('channels','userCreatedChannels') COLLATE utf8_persian_ci NOT NULL,
`channelOwnerUserId` int(11) NOT NULL,
`fileServerUrlId` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `channels`
--
ALTER TABLE `channels`
ADD PRIMARY KEY (`id`);
Error and notice:
This table does not contain a unique column. Features related to the grid edit, checkbox, Edit, Copy and Delete links may not work after saving.
Error
UPDATE `channels` SET `channelState` = '1' WHERE LIMIT 1
MySQL said: Documentation
#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 'LIMIT 1' at line 1
id of this table is unique and A_I, how can i resolve this problem?

SQL create table syntax

I do not undertstand what is the problem with this:
CREATE TABLE 'posts' (
'IdPost' int(11) NOT NULL AUTO_INCREMENT,
'IdUser' int(11) NOT NULL,
'name' varchar(45) CHARACTER SET latin1 NOT NULL,
'title' varchar(100) CHARACTER SET latin1 NOT NULL,
'type' tinyint(4) NOT NULL,
'address' varchar(30) CHARACTER SET latin1 NOT NULL,
'lat' varchar(10) NOT NULL,
'lon' varchar(10) NOT NULL,
'url' varchar(30) NOT NULL,
PRIMARY KEY ('IdPost')
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
I am getting this error on my server:
#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 ''posts' ( 'IdPost' int(11) NOT NULL AUTO_INCREMENT, 'IdUser' int(11) NOT NUL' at line 1
What is the problem?
Do not use the quotes for your table name. Also remove all the quotes from your column name too.
DEMO SQL FIDDLE
On a side note:-
From here:-
Quoting is useful when an identifier is an SQL reserved word or
contains spaces or other special characters. Quoting an identifier
also enables it to be entirely numeric, something not true of unquoted
identifiers. To include an identifier quote character within a quoted
identifier, double it.
Don't put your table or column names in quotes. You have to use backticks for reserved words which is not the case for this table.
CREATE TABLE posts
(
IdPost int(11) NOT NULL AUTO_INCREMENT,
IdUser int(11) NOT NULL,
name varchar(45) CHARACTER SET latin1 NOT NULL,
title varchar(100) CHARACTER SET latin1 NOT NULL,
type tinyint(4) NOT NULL,
address varchar(30) CHARACTER SET latin1 NOT NULL,
lat varchar(10) NOT NULL,
lon varchar(10) NOT NULL,
url varchar(30) NOT NULL,
PRIMARY KEY (IdPost)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
This can be an alternative:
CREATE TABLE `posts` (
`IdPost` int(11) NOT NULL AUTO_INCREMENT,
`IdUser` int(11) NOT NULL,
`name` varchar(45) CHARACTER SET latin1 NOT NULL,
`title` varchar(100) CHARACTER SET latin1 NOT NULL,
`type` tinyint(4) NOT NULL,
`address` varchar(30) CHARACTER SET latin1 NOT NULL,
`lat` varchar(10) NOT NULL,
`lon` varchar(10) NOT NULL,
`url` varchar(30) NOT NULL,
PRIMARY KEY (`IdPost`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
I would suggest to use back tilts instead of quotes