please give me recommendation my query does not working
SQL query:
CREATE TABLE `amenities` (
`amenities_id` int(11) NOT NULL auto_increment,
`pic` varchar(100) NOT NULL,
`des` text NOT NULL,
PRIMARY KEY (`amenities_id`)
) TYPE=MariaDB AUTO_INCREMENT=13
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 'TYPE=MariaDB AUTO_INCREMENT=13' at line 6
There is no type table option, you possibly want to define the table engine
and there is no mariadb engine try
CREATE TABLE amenities ( amenities_id int(11) NOT NULL auto_increment,
pic varchar(100) NOT NULL, des text NOT NULL, PRIMARY KEY (amenities_id) )
AUTO_INCREMENT=13,
engine=innodb
Or leave out the engine option if you want to default the table to the database engine/
Hope this works.
CREATE TABLE amenities (
amenities_id int(11) NOT NULL auto_increment,
pic varchar(100) NOT NULL,
des text NOT NULL,
PRIMARY KEY (amenities_id)
) AUTO_INCREMENT=13
The TYPE keyword was replaced by ENGINE long ago.
The ENGINEs are InnoDB, MyISAM, MEMORY, ARIA and possibly others. Not MySQL, nor MariaDB.
The error message ... near 'TYPE ... points exactly at or after the offending syntax: TYPE in this case. (Not AUTO_INCREMENT, which was later)
AUTO_INCREMENT=13 is produced by SHOW CREATE TABLE for possible reloading. However, it is rarely useful otherwise. It is also mostly harmless.
DROP TABLE IF EXISTS `amenities`;
CREATE TABLE `amenities` (
`amenities_id` int(11) NOT NULL AUTO_INCREMENT,
`pic` varchar(100) NOT NULL,
`des` text,
PRIMARY KEY (`amenities_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Create new Table amenities where amenities_id is a PRIMARY KEY that will be auto increment. another table field pic is a varchar data type and des is a text data type that is used for rich text.
Related
I ran into a new problem today, when I was dealing with a mysql query that works on 10.1.19-MariaDB localhost, but not on MySQL 5.7.21-0ubuntu0.16.04.1-log:
CREATE TABLE testing (
pageid INT UNSIGNED NOT NULL AUTO_INCREMENT,
position SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (pageid),
UNIQUE position (position)
) ENGINE=InnoDB CHARSET=utf8
In MySQL 5.6 it works without any hickups (fiddle), however, in MySQL 5.7.21 (fiddle) it throws:
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 'position (position)) ENGINE=InnoDB CHARSET=utf8' at line 1
I figured out a solution by replacing UNIQUE position (position) with UNIQUE (position).
But I am wondering, what the underlying problem is, why it works with the other db system, and I am not sure if my solution is correct.
MySQL doesn't allow you to create an index with the same name of the column
The following code works for MySQL (fiddle)
CREATE TABLE testing (
pageid INT UNSIGNED NOT NULL AUTO_INCREMENT,
position SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (pageid),
UNIQUE idx_position (position)
) ENGINE=InnoDB CHARSET=utf8
That's why it is so important to wrap field and table names in backticks in MySQL (and their derivatives):
Try this (same query and index names, only added backticks):
CREATE TABLE `testing` (
`pageid` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`position` SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (`pageid`),
UNIQUE `position` (`position`)
) ENGINE=InnoDB CHARSET=utf8;
Just a note, I'm pretty new to SQL.
I'm using MySQL and using the app SequelPro.
I receive this error when I try to make a table:
"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' at line 4"
This is the code I'm using to make my table:
CREATE TABLE klout_scores_3 (
id INT(11) NOT NULL AUTO_INCREMENT,
score INT(11)
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
score INT(11)
You want a comma , at end of that line.
Your query is being interpreted like this:
CREATE TABLE klout_scores_3 (
id INT(11) NOT NULL AUTO_INCREMENT,
score INT(11) PRIMARY KEY
(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The (id) part is really confusing to MySQL and it's raising an error right there. Although adding a , after the INT(11) part will fix it, a better solution is to move the declaration:
CREATE TABLE klout_scores_3 (
id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
score INT(11)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
It's a little concerning that you have a table name like klout_scores_3, as that suggests you have N of these tables. Relational database design and database normalization
rules strongly frowns on this, you should have a singular table with some kind of ..._id column to relate the scores to whatever record that 3 identifies.
I'm trying to put together a MySQL database for a forum, And when I try to make a section table I keep encountering a problem
#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 7
Here's the code:
CREATE TABLE sections (
sect_id INT(8) NOT NULL AUTO_INCREMENT,
sect_name VARCHAR(255) NOT NULL,
sect_desc VARCHAR(255) NOT NULL,
UNIQUE INDEX sect_name_unique (sect_name),
PRIMARY KEY (sect_id)
) TYPE=INNODB;
Use the following query
CREATE TABLE IF NOT EXISTS sections (
sect_id INT(8) NOT NULL AUTO_INCREMENT,
sect_name VARCHAR(255) NOT NULL,
sect_desc VARCHAR(255) NOT NULL,
UNIQUE INDEX sect_name_unique (sect_name),
PRIMARY KEY (sect_id)
) ENGINE=InnoDB
To mention the type of engine use ENGINE keyword.
I am trying to create a table from my command line (Debian), but it keeps saying I have an error in my syntax. To me it looks fine and I have got it checked by 2 different people who also cannot find the issue.
CREATE TABLE users (
id INT(6) UNSIGNED AUTO_INCREMENT,
uuid VARCHAR(32) NOT NULL,
key VARCHAR(50) NOT NULL
);
One guy said remove NOT NULL but I still had the same issue.
KEY is a reserved word try change with my_key
CREATE TABLE users (id INT( 6) UNSIGNED AUTO_INCREMENT,
uuid VARCHAR(32) NOT NULL,
my_key VARCHAR(50) NOT NULL,
PRIMARY KEY (`id`));
Sorry,
for an AUTO_INCREMENT Field you MUST have a key on this COLUMN.
So this works:
CREATE TABLE `user` (
`id` int(6) unsigned NOT NULL AUTO_INCREMENT,
`uuid` varchar(32) DEFAULT NULL,
`key` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
MySQL has lots of reserved keywords that cannot be used as column names. Here you are using key as a column name, and since it is a reserved keyword in MySQL, you need to change the name of the column to something that is not a reserved keyword.
You can find a full list of reserved keywords that cannot be used as a column name here.
The column name "key" you used for the third column is a reserved word, all you have to do is change the name.
Well, one probably can't know all the existing keywords in a programming language but one can help himself/herself by using colour-code enabled text editor or Integrated Development Environment (IDE) when writing codes. It helps a lot.
I have a problem when I am trying to create a new table in phpmyadmin in a database. The code is:
DROP TABLE IF EXISTS phpcrawler_links;
CREATE TABLE phpcrawler_links (
id int(11) NOT NULL auto_increment,
site_id int(11) NOT NULL default 0,
depth int(11) NOT NULL default 0,
url text NOT NULL,
url_title text,
url_md5 varchar(255) NOT NULL,
content text NOT NULL,
content_md5 varchar(255) NOT NULL,
last_crawled datetime,
crawl_now int(11) NOT NULL default 1,
PRIMARY KEY (id),
KEY idx_site_id(site_id),
KEY idx_url (url(255)),
KEY idx_content_md5(content_md5),
FULLTEXT ft_content(content),
KEY idx_last_crawled(last_crawled)
);
DROP TABLE IF EXISTS words;
CREATE TABLE words (
id int(11) NOT NULL,
word varchar(255) NOT NULL
);
The problem seems to be on this line:
last_crawled datetime,
The error I get is:
#1214 - The used table type doesn't support FULLTEXT indexes
If anyone can help me out with this I will be greatfull!
Google rules!
Only MyISAM tables support fulltext indicies.
http://forums.mysql.com/read.php?107,194405,194677
you cannot add index to that DB if the table is Innodb, you must change the engine to MyISAM or change the data type to int
seems you are using an old version of MySQL, as from MySQL 5.6, InnoDB support fulltext index already.