ALTER TABLE table_name AUTO_INCREMENT = 1000; gives me syntax error - mysql

this is my table export:
CREATE TABLE IF NOT EXISTS `order` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`comment` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`shipping_cost` double DEFAULT NULL,
`customer_id` int(11) NOT NULL,
`delivery_type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`invoice_nr` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `order_customer_id_index` (`customer_id`),
KEY `order_invoice_nr_index` (`invoice_nr`),
KEY `order_created_at_index` (`created_at`),
KEY `order_updated_at_index` (`updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
when I run now:
ALTER TABLE order AUTO_INCREMENT=1000;
I get:
#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 'order AUTO_INCREMENT=1000' at line 1
the table is empty!
mysql version: 5.5.44-0ubuntu0.14.04.1
someone has an idea what could cause me this problem?
if I put for example this:
ALTER TABLE asdasdfasdfasdf AUTO_INCREMENT=1000;
I get
1146 - Table 'mydb.asdasdfasdfasdf' doesn't exist

Try:
ALTER TABLE `order` AUTO_INCREMENT=1000;
Order is a reserved word, it's trying to order...

Related

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB

CREATE TABLE IF NOT EXISTS `tbl_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` double(11) NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
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 ') NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT
CHARSET=latin1 AUTO_INCRE' at line 5
try using float without the number of showing digit
CREATE TABLE IF NOT EXISTS `tbl_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` double NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
and for price could be you need a fixed decimal length so you should use decimal
CREATE TABLE IF NOT EXISTS `tbl_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` decimal(10,2) NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
You're missing a value in your double specifier:
`price` double(11) NOT NULL
It needs both the total digits and the digits following the decimal. Something like:
`price` double(11,2) NOT NULL
Though for currency values you may be better off using decimal instead:
`price` decimal(11,2) NOT NULL
As this uses a more fixed precision. Using a double may result in unexpected calculation results from how floating point arithmetic works.

Why is sql not letting me create this table?

I'm trying to migrate a db
from: MySQL Distrib 5.5.60-MariaDB, for Linux (x86_64)
to: MySQL 5.5.4, UNIX
I tried importing the db as a zip package and it started throwing errors so now I'm trying to re-create each table one at a time on phpMyAdmin.
The query below is throwing a #1064 Syntax error, and I'm having trouble figuring out the issue.
MySQL Said:
#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 '(2) NOT NULL DEFAULT CURRENT_TIMESTAMP(2) ON UPDATE CURRENT_TIMESTAMP(2),
`st' at line 6
I'm looking at line 6, trying to find any reserved words, missing data, typos, and or obsolete commands but no luck.
CREATE TABLE `tblmoto_auth_policies` (
`policy_id` int(11) NOT NULL AUTO_INCREMENT,
`policy_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`policy_desc` text COLLATE utf8_unicode_ci NOT NULL,
`policy_url` text COLLATE utf8_unicode_ci NOT NULL,
`date_added` timestamp(2) NOT NULL DEFAULT CURRENT_TIMESTAMP(2) ON UPDATE CURRENT_TIMESTAMP,
`status` smallint(2) NOT NULL DEFAULT '1',
PRIMARY KEY (`policy_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
I could use some help.
Thanks in advance.
CURRENT_TIMESTAMP is not good
Try this:
CREATE TABLE `tblmoto_auth_policies` (
`policy_id` int(11) NOT NULL AUTO_INCREMENT,
`policy_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`policy_desc` text COLLATE utf8_unicode_ci NOT NULL,
`policy_url` text COLLATE utf8_unicode_ci NOT NULL,
`date_added` timestamp(2) NOT NULL DEFAULT CURRENT_TIMESTAMP(2) ON UPDATE CURRENT_TIMESTAMP(2),
`status` smallint(2) NOT NULL DEFAULT '1',
PRIMARY KEY (`policy_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
This works in SQL Fiddle:
CREATE TABLE `tblmoto_auth_policies` (
`policy_id` int(11) NOT NULL AUTO_INCREMENT,
`policy_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`policy_desc` text COLLATE utf8_unicode_ci NOT NULL,
`policy_url` text COLLATE utf8_unicode_ci NOT NULL,
`date_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`status` smallint(2) NOT NULL DEFAULT '1',
PRIMARY KEY (`policy_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
i.e., remove the precision (the (2)) from the definition of the date_added column.
TIMESTAMP(2) is valid syntax, but not in combination with the DEFAULT CURRENT_TIMESTAMP nor ON UPDATE CURRENT_TIMESTAMP auto-initializers.

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?

incomprehensible error on this simple create table query

I've just exported the CREATE sql of a singular table using phpmyadmin. this is the result:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`register_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`account_type` int(11) NOT NULL,
`active` int(11) NOT NULL,
`email` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`login` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(200) COLLATE utf8_unicode_ci NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
But when i run this code on the very phpmyadmin i receive this 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 '(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREME' at line 14
I have tried many ways, but my skills aren't enough.
You forgot to add comma before PRIMARY KEY (id)
`name` varchar(200) COLLATE utf8_unicode_ci NOT NULL, -- <== this
PRIMARY KEY (`id`)
add comma and it will work, see this fiddle (click link)

Mysql Create Table error on second CREATE statement [duplicate]

This question already has answers here:
node-mysql multiple statements in one query
(3 answers)
Closed 5 years ago.
I'm trying to write a script to import a Mysql DB structure. I've exported the database SQL via PhpMyAdmin, and node npm model sqldump. Both produce the same error when trying to create the second table. This doesn't seem to be table-specific - I can mix the tables around (I have 20 tables in this DB) and always hit the same error on the second CREATE TABLE statement.
Can anyone point me towards something stupid I'm missing, please?
The error is:
{ Error: 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 'CREATE TABLE IF NOT EXISTS `autoresponses` (
`id` bigint(20) NOT NULL AUTO_INC' at line 14
at PromiseConnection.query (D:\dev-mysql-update\node_modules\mysql2\promise.js:75:20)
at D:\dev-mysql-update\index.js:157:7
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
message: '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 \'CREATE TABLE IF NOT EXISTS `autoresponses` (\n `id` bigint(20) NOT NULL AUTO_INC\' at line 14',
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlState: '#42000' }
The first two tables are:
CREATE TABLE IF NOT EXISTS `autoresponders` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`uuid` char(36) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
`archived` tinyint(1) NOT NULL DEFAULT '0',
`title` varchar(255) DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`client_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `client_id` (`client_id`),
CONSTRAINT `autoresponders_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `autoresponses` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`uuid` char(36) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
`archived` tinyint(1) NOT NULL DEFAULT '0',
`hours_delay` int(11) DEFAULT NULL,
`status` varchar(255) DEFAULT 'active',
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`autoresponder_id` bigint(20) DEFAULT NULL,
`notification_id` bigint(20) DEFAULT NULL,
`client_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `autoresponses_autoresponder_id_notification_id_unique` (`autoresponder_id`,`notification_id`),
KEY `notification_id` (`notification_id`),
CONSTRAINT `autoresponses_ibfk_1` FOREIGN KEY (`autoresponder_id`) REFERENCES `autoresponders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `autoresponses_ibfk_2` FOREIGN KEY (`notification_id`) REFERENCES `notifications` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Thanks in advance,
Andy
Your table name should be inside your parenthesis.