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.
Related
I am trying to create a table which references two other tables that I have planned to make, but have not made yet. I am wondering if that is the issue here or if there is a syntax error that I am missing. If anyone can help me out it would be greatly appreciated
mysql> CREATE TABLE items (
items$id INT NOT NULL AUTO_INCREMENT,
sales$id INT NOT NULL AUTO_INCREMENT,
img$id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
desc VARCHAR(255) NOT NULL,
PRIMARY KEY(items$id),
FOREIGN KEY(sales$id) REFERENCES sales(sales$id),
FOREIGN KEY(img$id) REFERENCES image(img$id)
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 'desc VARCHAR(255) NOT NULL,
PRIMARY KEY(items$id),
FOREIGN KEY(sales$id) REFEREN' at line 6
I tried to remove the references, as in just do 'FOREIGN KEY(sales$id)' and 'FOREIGN KEY(img$id)' to see if that would work (I am new to mysql), but that also did not work. Any help is appreciated.
The problem is your field name: desc
desc is a keyword in mysql see here
Your sql would be better like this:
CREATE TABLE items ( items$id INT NOT NULL AUTO_INCREMENT, sales$id INT NOT NULL AUTO_INCREMENT, img$id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, descr VARCHAR(255) NOT NULL, PRIMARY KEY(items$id),
FOREIGN KEY(sales$id) REFERENCES sales(sales$id),
FOREIGN KEY(img$id) REFERENCES image(img$id))
Ps: you missed closing bracket ')' at the end of your sql query.
I have this code:
CREATE TABLE Company ( Comp_Code INT(5) NOT NULL AUTO_INCREMENT=1000, Comp_Name VARCHAR(15) NOT NULL, PRIMARY KEY (Comp_Code) );
but when i run it in MYSQL from WAMPServer it gives an 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 '=1000,
Comp_Name VARCHAR(15) NOT NULL,
PRIMARY KEY (Comp_Code)
)' at line 2
Why is this happening? I can't seem to find any solution to this particular issuer.
AUTO_INCREMENT is column option.
Initial AUTO_INCREMENT=1000 value is table option.
CREATE TABLE Company (
Comp_Code INT(5) NOT NULL AUTO_INCREMENT, -- specify that the column is AI
Comp_Name VARCHAR(15) NOT NULL,
PRIMARY KEY (Comp_Code)
) AUTO_INCREMENT=1000; -- specify initial AI value
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.
I'm trying to get this to work but I don't understand how SQL works outside of the basics. Can you find the error in this?
CREATE TABLE lil_urls (
id varchar(255) NOT NULL default '',
url text,
date timestamp(14) NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
I'm currently getting this error in PhPMyAdmin:
#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 '(14) NOT NULL,
PRIMARY KEY (id)' at line 4
Thanks for your help!
Correct syntax is
CREATE TABLE lil_urls (
id varchar(255) NOT NULL default '',
url text,
date timestamp NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM;
TYPE is no longer used and you need to use as ENGINE
And no need to specify length for timestamp
I have a MySQL database:
CREATE TABLE `users votes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userid` int(11) NOT NULL,
`forumtopicid` int(11) DEFAULT NULL,
`replyid` int(11) DEFAULT NULL
)
I'm trying to create two unique constraints:
CREATE UNIQUE INDEX index_first
ON `users votes`(userid, forumtopicid, replyid)
WHERE forumtopicid IS NOT NULL;
CREATE UNIQUE INDEX index_second
ON `users votes`(userid, replyid)
WHERE forumtopicid IS NULL;
This is throwing an error that I'm unsure how to fix. Is it not possible to add a WHERE clause for MySQL constraints?
#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 'WHERE forumtopicid IS NOT NULL' at line 3
That's correct - you cannot use WHERE in CREATE INDEX statements (in mysql).