CREATE TABLE 1
(text longtext(4,294,967,295),
date VARCHAR(50),
time VARCHAR(50),
id INT(11 ) NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY ( `id` )
What is wrong with the above SQL statement? I keep getting an 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 '(4,294,967,295), date VARCHAR(50), time VARCHAR(50), id INT( 11 ) NOT NULL AU' at line 3
1 is a lousy name for a table. If you use it, you need to escape the name. Also, commas aren't allow in lengths for character fields and longtext doesn't need a length anyway:
CREATE TABLE `1`
(text longtext,
date VARCHAR(50),
time VARCHAR(50),
id INT(11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY
)
And, you don't "add" a primary key. You just declare it.
Related
I am trying to create a table in MySQL with the query
CREATE TABLE ofRosterGroups (
rosterID BIGINT NOT NULL,
rank TINYINT NOT NULL,
groupName VARCHAR(255) NOT NULL,
PRIMARY KEY (rosterID, rank),
INDEX ofRosterGroup_rosterid_idx (rosterID)
);
but seems like it is throwing error everytime I made updates too. I don't know what is going wrong with it.
Error coming up is
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 'rank TINYINT NOT NULL, groupName
VARCHAR at line 3
MySQL 8.0.2 added support for the window rank function, making it a reserverd word.
You could escape it using backticks (`):
CREATE TABLE ofRosterGroups (
rosterID BIGINT NOT NULL,
`rank` TINYINT NOT NULL, -- Here
groupName VARCHAR(255) NOT NULL,
PRIMARY KEY (rosterID, `rank`), -- And here
INDEX ofRosterGroup_rosterid_idx (rosterID)
);
But it may be a better idea to just use a name that isn't a reserved word, such as rosterRank instead of rank:
CREATE TABLE ofRosterGroups (
rosterID BIGINT NOT NULL,
rosterRank TINYINT NOT NULL, -- Here
groupName VARCHAR(255) NOT NULL,
PRIMARY KEY (rosterID, rosterRank), -- And here
INDEX ofRosterGroup_rosterid_idx (rosterID)
);
I am getting a SQL query syntax error while creating a table. Here is the SQL query:
CREATE TABLE ACCOUNT (
ACCNO NUMBER(5) NOT NULL,
NAME VARCHAR(20) NOT NULL,
BA L NUMBER(8,2) NOT NULL,
CREATION-DT DATE NOT NULL,
PRIMARY KEY ( ACCNO )
);
Here is 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 'NUMBER(5) NOT NULL.
What is wrong with my syntax?
Using SQLfiddle you can see this is not valid.
You have multiple problems with your syntax; invalid data types, invalid column names, etc. You can encapsulate the invalid names in backticks but then you will have to remember to encapsulate them later.
Instead of Number you probably meant numeric but i would suggest trying Integer instead.
Or just try this:
CREATE TABLE ACCOUNT (
ACCNO INTEGER(5) NOT NULL,
NAME VARCHAR(20) NOT NULL,
BAL INTEGER(8) NOT NULL,
CREATIONDT DATE NOT NULL,
PRIMARY KEY ( ACCNO )
);
NUMBER is not a valid datatype in MySQL, you should choose the one from the list (maybe you've meant NUMERIC).
You should also escape some identifiers (in your case, column names BA L, which includes a space within it, and CREATION-DT, which includes a dash) with backticks ` in MySQL:
CREATE TABLE `ACCOUNT` (
`ACCNO` NUMERIC(5) NOT NULL,
`NAME` VARCHAR(20) NOT NULL,
`BA L` NUMERIC(8,2) NOT NULL,
`CREATION-DT` DATE NOT NULL,
PRIMARY KEY ( `ACCNO` )
);
SQLFiddle
I create a physical model in powerdesigner
and then generate the code for mysql5, and now in
phpmyadmin Im getting 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 'create table CARD
Do you see why this can be happening?
Im creating my tables like this:
create table books
(
COD_BOOK int not null auto_increment,
TITLE_BOOK varchar(50),
ISBN _BOOK varchar(20),
CATEGORY_BOOK varchar(20),
primary key (COD_BOOK)
)
And the problem seems like is in this part: int not null auto_increment,
You're missing the semi-colon at the end of your create statement. This makes the first line of the create statement for the next table an error which is what that error message is trying to tell you.
create table books
(
COD_BOOK int not null auto_increment,
TITLE_BOOK varchar(50),
ISBN_BOOK varchar(20),
CATEGORY_BOOK varchar(20),
primary key (COD_BOOK)
);
The problem is the space after ISBN:
create table books
(
COD_BOOK int not null auto_increment,
TITLE_BOOK varchar(50),
ISBN_BOOK varchar(20),
CATEGORY_BOOK varchar(20),
primary key (COD_BOOK)
)
Here is a SQL Fiddle.
#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 ')
)' at line 7
i have got that problem, but i cannot realize where is the mistake.
i've read mysql error documentation, and it says the error is about parse. but i still dont understand yet, thank for your help.
here is an sql query :
CREATE TABLE IF NOT EXISTS produk_detil (
id_produk varchar( 10 ) NOT NULL ,
short_desc text NOT NULL ,
long_desc text NOT NULL ,
min_beli int( 5 ) ,
jml_qty int( 10 ) ,
berat double( 7 )
);
CREATE TABLE IF NOT EXISTS harga(
id_produk varchar(10) NOT NULL,
tgl_aktif date NOT NULL,
tgl_deaktif date,
nominal_harga double(10)
);
CREATE TABLE IF NOT EXISTS testimonials(
id_testimoni varchar(10),
id_produk varchar(10),
id_user varchar(10),
isi_konten text,
tgl_buat date,
tgl_modifikasi date
);
CREATE TABLE IF NOT EXISTS order(
id_order varchar(10) NOT NULL PRIMARY KEY,
id_user varchar(10) NOT NULL,
tgl_order date,
total_bayar double(15),
jml_item int(10)
);
CREATE TABLE IF NOT EXISTS order_detil(
id_order varchar(10) NOT NULL,
id_produk varchar(10) NOT NULL,
harga double(15) NOT NULL,
qty int(10)
);
You have to provide the amount of decimal places for double, e. g. double (7, 2 ) means your number has a total of 7 digits, whereof 2 are decimal places, just like 10233,95
btw I would strongly recommend to get attuned to use english column names.. there will be one day people who need to understand your DB scheme and do not speak your language
You need to provide decimal places for the double. For eg: berat double( 7 ,2) will work fine
Check out the syntax for declaring columns with double datatype.
you have to indicate the length of the whole number and the length of decimal part
nominal_harga double(10,10)
read more here
I'm trying to create a Temp Table that has a key field that auto increments. But I keep running into a syntax error.
Here's what I'm trying:
CREATE TEMPORARY TABLE
RETURN_ARTISTS
(KEY INT(11) NOT NULL AUTO_INCREMENT,
ARTIST_1_KEY INT(11),
ARTIST_2_KEY INT(11));
INSERT INTO RETURN_ARTISTS (1,1);
DELETE TABLE RETURN_ARTISTS;
And here's the error I keep getting:
Err] 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 'INT(11) NOT NULL AUTO_INCREMENT,
ARTIST_1_KEY INT(11),
ARTIST_2_KEY INT(' at line 3
First of all, key is a reserved word, escape it with `
Secondly, when using auto_increment column, that column must be defined as a key.
CREATE TEMPORARY TABLE
`RETURN_ARTISTS`
(`KEY` INT(11) NOT NULL AUTO_INCREMENT,
ARTIST_1_KEY INT(11),
ARTIST_2_KEY INT(11),
KEY (`KEY`));
key is a reserved word, so you'll have to escape it:
(`KEY` INT(11) NOT NULL AUTO_INCREMENT,
^---^--- escapes
or, preferably, use a different field name.