would really like some help trying to figure out what I am doing wrong here. I have searched through several other questions but could not find anything wrong in my CREATE statement that others had.
CREATE TABLE Client(
'Client_ID' INT NOT NULL AUTO_INCREMENT,
'Client_Name' VARCHAR(30) NOT NULL,
'Class' VARCHAR(50) NOT NULL,
'Pre-Billing' BOOLEAN NOT NULL DEFAULT 0,
'Email' VARCHAR(100),
'Phone_Number' VARCHAR(30) NOT NULL,
'Address' VARCHAR(150) NOT NULL,
'Last_Updated' timestamp default now() on update now(),
'Date_Added' timestamp default now(),
PRIMARY KEY ('Client_ID')
);
The error I am getting is
Error Code: 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 ''Client_ID' INT NOT NULL AUTO_INCREMENT, 'Client_Name' VARCHAR (30) NOT NULL, ' at line 2
If you could please advise that would be greatly appreciated, thank you.
If you remove the single quotes around the column names and change the hyphen in "Pre-Billing" to an underscore "Pre_Billing", this should fix it.
Related
I am not able to find out what is the exact issue. When I remove index param from below mentioned query and try to insert the data it works fine, but trying to add index cause an error.
Here is my table schema:
CREATE TABLE IF NOT EXISTS `address_list` (
`email` varchar(100) NOT NULL,
`currency_name` varchar(50) NOT NULL,
`address` varchar(50) NOT NULL,
`label` varchar(100) NOT NULL,
`index` int DEFAULT 0,
`address_type` varchar(50) NOT NULL,
`balance` varchar(500) DEFAULT "0.0",
`timestamp` TIMESTAMP default CURRENT_TIMESTAMP
)
and here is my insert query :
insert into address_list (email,currency_name,address,label,index,address_type) Values ('abc#gmail.com','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X','test address',3,'wallet');
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 'index) Values ('abc#gmail.com','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X'' at line 1
index is a reserved word in mysql; rename your column to something else, or else place it in backticks where you want to use it:
insert into address_list (email,currency_name,address,label,`index`,address_type) Values ('abc#gmail.com','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X','test address',3,'wallet');
See https://dev.mysql.com/doc/refman/8.0/en/keywords.html
I am having a very strange issue with creating a table in mySQL. Every time I run the file I get this error:
"ERROR 1064 (42000) at line 36 in file: 'QStoreDB.sql': 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 ')' at line 8"
For this section of code:
CREATE TABLE customers
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(45) NOT NULL,
address1 VARCHAR(160) NOT NULL,
address2 VARCHAR(160) NOT NULL,
cart INT,
);
This is the third table in my file. The other 2 are created with no issue using the same format. I have tried removing all comments, as you can see I have removed all of my constraints but even when I input the data in its most basic form (ie whats writen above this paragraph) it still doesn't run. I have also tried putting my field names in `` to no avail.
I am at a complete loss and scouring the internet has not helped me so I'm hoping some one here has experienced this as can point me in the right direction.
Whilst defining PRIMARY KEY you do not have to write INT NOT NULL
CREATE TABLE customers
(
id PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(45) NOT NULL,
address1 VARCHAR(160) NOT NULL,
address2 VARCHAR(160) NOT NULL,
cart INT
);
And there shouldn't be a comma at the end.
I can't tell what is wrong with this query.
create table roles
(
id int unsigned not null auto_increment
,name varchar(32) not null
,phone varchar(256) not null
,primary key (id)
)
engine=innodb
default charset=utf8;
When I try to run it, I get:
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 auto_increment ,role_id int unsigned ' at
line 3
Using MySQL 5.7
Thanks for the advice, tadman
Turns out I had a tab between "int unsigned" instead of a space. Replaced the tab with a space and it worked just fine.
That was driving me crazy for almost 2 hours.
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
Just started playing with MySQL and I've already made stupid mistake which is somewhere in there; that's what I need to figure out:
CREATE TABLE `txts` (
`ID` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(75) NOT NULL,
`content` VARCHAR(MAX) NOT NULL,
`lastupdate` DATE NOT NULL default '0000-00-00',
PRIMARY KEY (`ID`)
)ENGINE=MyISAM DEFAULT CHARSET=utf8;
It gives:
#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 'MAX) NOT NULL,
`lastupdate` DATE NOT NULL default '0000-00-00', PRIMARY KEY ' at line 4
I know it's extremely stupid but I can't see a single mistake in it.
VARCHAR(MAX)
MySQL does not support the use of MAX.
Use an real number value.
Per Google:
The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions.