phpMyadmin - Error #1064 - mysql

When trying to create this table in my db, I get an 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 'unsigned NOT NULL default '0',
PRIMARY KEY (reminder_id), KEY
reminder_id (rem' at line 5
CREATE TABLE reminder_events (
reminder_id bigint(20) unsigned NOT NULL auto_increment,
reminder_name varchar(255) NOT NULL default '',
reminder_desc text,
reminder_date varchar(8) unsigned NOT NULL default '0',
PRIMARY KEY (reminder_id),
KEY reminder_id (reminder_id)
) TYPE=MyISAM;
Can anyone see what I'm doing wrong?

The problem is that you're trying to define a text field (varchar) as being unsigned, which is something that can only apply to a numerical field.
i.e.: "reminder_date varchar(8) unsigned NOT NULL default '0'," makes no sense.
However, as the field is called "reminder_date", I'm guessing you're attempting to store a date, in which case you really want to use MySQLs DATE field type.
e.g.: "reminder_date DATE NOT NULL,"
Additionally, if you're going to want to search on any of these fields, you should also add some indexes to speed up the searches. So, if you wanted to be able to search on the name and date, you could use:
CREATE TABLE reminder_events (
reminder_id bigint(20) unsigned NOT NULL auto_increment,
reminder_name varchar(255) NOT NULL DEFAULT '',
reminder_desc text,
reminder_date DATE NOT NULL,
PRIMARY KEY (reminder_id),
KEY reminder_id (reminder_id),
KEY reminder_name (reminder_name),
KEY reminder_date (reminder_date)
) TYPE=MyISAM;

Just remove unsigned.
CREATE TABLE reminder_events (
reminder_id bigint(20) unsigned NOT NULL auto_increment,
reminder_name varchar(255) NOT NULL default '',
reminder_desc text,
reminder_date varchar(8) NOT NULL default '0',
PRIMARY KEY (reminder_id),
KEY reminder_id (reminder_id)
) TYPE=MyISAM;

Write ENGINE instead of TYPE
CREATE TABLE reminder_events (
reminder_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
reminder_name VARCHAR(255) NOT NULL DEFAULT '',
reminder_desc TEXT,
reminder_date VARCHAR(8) NOT NULL DEFAULT '0',
PRIMARY KEY (reminder_id),
KEY reminder_id (reminder_id)
) ENGINE=MYISAM;

Related

Problems with sql MariaDB (1064)

I can't solve this error showing on my database:
check the manual that corresponds to your MariaDB server version for
the right syntax to use near 'CREATE TABLE tf_links' at line 12
My SQL file code is:
CREATE TABLE tf_cookies (
cid int(10) NOT NULL auto_increment,
uid int(10) NOT NULL default '0',
host VARCHAR(255) default NULL,
data VARCHAR(255) default NULL,
PRIMARY KEY (cid)
) ENGINE=MyISAM;
--
-- tf_links
--
CREATE TABLE tf_links (
lid int(10) NOT NULL auto_increment,
url VARCHAR(255) NOT NULL default '',
sitename VARCHAR(255) NOT NULL default 'Old Link',
sort_order TINYINT(3) UNSIGNED default '0',
PRIMARY KEY (lid)
) ENGINE=MyISAM;

create table error in mysql. 1071 error

hi all can some one plz help me,
while creating table in mysql i am getting the following error
MySQL error 1071: Specified key was too long; max key length is 767 bytes
my table definition is as follows.
CREATE TABLE oauth_consumer (id char(36) NOT NULL ,
name varchar(255) NULL ,
date_entered datetime NULL ,
date_modified datetime NULL ,
modified_user_id char(36) NULL ,
created_by char(36) NULL ,
description text NULL ,
deleted bool DEFAULT '0' NULL ,
assigned_user_id char(36) NULL ,
c_key varchar(255) NULL ,
c_secret varchar(255) NULL,
PRIMARY KEY (id),
UNIQUE ckey (c_key)
);
No problem in your query. May be you are running old version of MySql. Use new version. If you are using new version try to use following query to create table
CREATE TABLE `oauth_consumer` (
`id` CHAR(36) NOT NULL,
`name` VARCHAR(255) NULL DEFAULT NULL,
`date_entered` DATETIME NULL DEFAULT NULL,
`date_modified` DATETIME NULL DEFAULT NULL,
`modified_user_id` CHAR(36) NULL DEFAULT NULL,
`created_by` CHAR(36) NULL DEFAULT NULL,
`description` TEXT NULL,
`deleted` TINYINT(1) NULL DEFAULT '0',
`assigned_user_id` CHAR(36) NULL DEFAULT NULL,
`c_key` VARCHAR(255) NULL DEFAULT NULL,
`c_secret` VARCHAR(255) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `ckey` (`c_key`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB;
First of all, your database character set is most likely set to utf8, so your 255 characters get blown up to 765 characters; though close, that's not greater than the imposed limit of 767, but it gives an idea of why you're hitting that limit nonetheless.
Regardless, it's not recommended to use such a wide key; you could calculate an md5 or sha1 of the value and use that for the unique key instead (btw, you should use the binary representation of the hash).

SQL Syntax error - can't find the error [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
CREATE TABLE 'categories'(
'id' SMALLINT NOT NULL AUTO_INCREMENT,
'category' VARCHAR(30) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE KEY 'category' ('category')
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE 'orders' (
'id' INT UNSIGNED NOT NULL AUTO_INCREMENT,
'user_id' INT UNSIGNED NOT NULL,
'transaction_id' VARCHAR(19) NOT NULL,
'payment_status' VARCHAR(15) NOT NULL,
'payment_amount' DECIMAL(6,2) UNSIGNED NOT NULL,
'payment_date_time' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ('id'),
KEY 'user_id' ('user_id')
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE 'pages' (
'id' MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
'category_id' SMALLINT UNSIGNED NOT NULL,
'title' VARCHAR(100) NOT NULL,
'description' TINYTEXT NOT NULL,
'content' LONGTEXT NOT NULL,
'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ('id'),
KEY 'category_id' ('category_id'),
KEY 'creation_date' ('date_created')
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE 'pdfs' (
'id' SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
'tmp_name' CHAR(40) NOT NULL,
'title' VARCHAR(100) NOT NULL,
'description' TINYTEXT NOT NULL,
'file_name' VARCHAR(40) NOT NULL,
'size' MEDIUMINT UNSIGNED NOT NULL,
'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ('id'),
UNIQUE KEY 'tmp_name' ('tmp_name'),
KEY 'date_created' ('date_created')
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE 'users' (
'id' INT UNSIGNED NOT NULL AUTO_INCREMENT,
'type' ENUM ('member','admin') NOT NULL,
'username' VARCHAR(30) NOT NULL,
'email' VARCHAR(80) NOT NULL,
'pass' VARBINARY(32) NOT NULL,
'first_name' VARCHAR(20) NOT NULL,
'last_name' VARCHAR (40) NOT NULL,
'date_expires' DATE NOT NULL,
'date_created' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
'date_modified' TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY ('id'),
UNIQUE KEY 'username' ('username'),
UNIQUE KEY 'email' ('email')
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
.............................................................................
I cannot find the SQL error here.
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 ''categories' ('id' SMALLINT NOT NULL AUTO_INCREMENT, 'category' VARCHAR(30) NOT' at line 1
Please help. I am using MySQL 4.4.x on a shared server.
You're surrounding your table and column names with ', it should be ` (backtick)
CREATE TABLE `categories`
(`id` SMALLINT NOT NULL AUTO_INCREMENT,
`category` VARCHAR(30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `category` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Get rid of your single quotes or as #Joachim Isaksson said, use backticks `.
CREATE TABLE categories (id SMALLINT NOT NULL AUTO_INCREMENT, category VARCHAR(30) NOT NULL, PRIMARY KEY (id), UNIQUE KEY(category) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Also next time, simplify your problem. You have a problem with the first CREATE TABLE statement. There is no need to print everything else. Also some formatting would be nice too :-).

Error in SQL Syntax (MYSQL 5.0)

Does anybody know what is wrong in this MYSQL 5.0 syntax?
CREATE TABLE IF NOT EXISTS target (
_id int(11) NOT NULL AUTO_INCREMENT,
time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
map_id int(11) DEFAULT NULL,
left int(11) DEFAULT NULL,
top int(11) DEFAULT NULL,
status tinyint(1) NOT NULL,
temperature int(11) DEFAULT NULL,
humidity float DEFAULT NULL,
lum int(11) DEFAULT NULL,
PRIMARY KEY (_id),
FOREIGN KEY (map_id) REFERENCES map(id) ON DELETE CASCADE
)
I'll show you the error:
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 'left INTEGER DEFAULT NULL,
top INTEGER DEFAULT NULL,
status tinyint(1) NOT' at line 5
Because left is a MySQL 5.0 reserved word. Also, even though you can escape the field name, it's never a great idea to use reserved words in a table definition.
you must write it like this:
CREATE TABLE IF NOT EXISTS target (
_id int(11) NOT NULL AUTO_INCREMENT,
time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
map_id int(11) DEFAULT NULL,
`left` int(11) DEFAULT NULL,
top int(11) DEFAULT NULL,
status tinyint(1) NOT NULL,
temperature int(11) DEFAULT NULL,
humidity float DEFAULT NULL,
lum int(11) DEFAULT NULL,
PRIMARY KEY (_id),
FOREIGN KEY (map_id) REFERENCES map(id) ON DELETE CASCADE
)
look at the `` (backticks) characters in left row !
You're using reserved words as field names. You can do that, but then you have to properly escape them, like this:
CREATE TABLE IF NOT EXISTS target (
`_id` int(11) NOT NULL AUTO_INCREMENT,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`map_id` int(11) DEFAULT NULL,
`left` int(11) DEFAULT NULL,
`top` int(11) DEFAULT NULL,
`status` tinyint(1) NOT NULL,
`temperature` int(11) DEFAULT NULL,
`humidity` decimal(13,2) DEFAULT NULL,
`lum` int(11) DEFAULT NULL,
PRIMARY KEY (_id),
FOREIGN KEY (map_id) REFERENCES map(id) ON DELETE CASCADE
)
My advise would be to avoid reserved names.

Create Table Syntax Error

I received a MySQL data dump and am trying to insert the data into a set of temporary tables. The creation statement for the first table is shown below. When I run this I receive the error: "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 ''temp_books'( 'ID'int( 11 ) NOT NULL AUTO_INCREMENT, 'start'varchar( 20 ) ' at line 1". I've checked the documentation for MySQL syntax, and I don't see that the problem is.
CREATE TABLE 'temp_books' (
'ID' int(11) NOT NULL AUTO_INCREMENT,
'start' varchar(20) NOT NULL,
'customer_id' int(11) NOT NULL DEFAULT '0',
'total_num' int(11) NOT NULL,
'amount' double(5,2) NOT NULL DEFAULT '0.00',
'changed' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ('ID'),
UNIQUE KEY 'start' ('start')
) ENGINE=MyISAM AUTO_INCREMENT=4853 DEFAULT CHARSET=latin1;
You shouldn't put single-quotes on your identifiers. If you're going to quote them use the "back tick" character (“`”). You can also use double-quotes but you have to specify that mode:
SET sql_mode='ANSI_QUOTES';
http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
I've ALWAYS had issues with CREATE TABLE. Not sure why. Takes some trial-and-error.
Try this:
CREATE TABLE temp_books (
ID int(11) NOT NULL AUTO_INCREMENT,
start varchar(20) NOT NULL,
customer_id int(11) NOT NULL DEFAULT '0',
total_num int(11) NOT NULL,
amount double(5,2) NOT NULL DEFAULT '0.00',
changed timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (ID),
UNIQUE KEY start (start)
) ENGINE=MyISAM AUTO_INCREMENT=4853 DEFAULT CHARSET=latin1;
I had to delete the quote marks, as well as the default for the changed field, as well as the default charset. Hopefully that won't affect the data.
Here's another way of writing it that might work for some: (left away most of the columns for brevity)
create table temp_books
(
id int not null,
start varchar(255) null,
constraint six_cb_datasource_pk
primary key (id)
);