I am having the following error when trying to execute the following code in phpMyAdmin. I am using WAMP Server with MySQL version 5.5.8 ::
The error is:
#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 'NUMERIC(6) not null, payee VARCHAR2(20) not null, amount DECIMAL(6,2) no' at line 3
the SQL is:
CREATE TABLE checks
(
check NUMERIC(6) not null,
payee VARCHAR2(20) not null,
amount DECIMAL(6,2) not null,
remarks VARCHAR2(20) not null
)
EDIT
I am also trying to execute this but it gives also error:
CREATE TABLE deposits
(
deposit NUMBER(8),
whopaid VARCHAR(25),
amount DECIMAL(6,2),
remarks VARCHAR(20)
)
You need to escape check with backticks since it is a reserved word. And in MySQL there is no varchar2 data type, just varchar.
CREATE TABLE checks
(
`check` NUMERIC(6) not null,
payee VARCHAR(20) not null,
amount DECIMAL(6,2) not null,
remarks VARCHAR(20) not null
)
Also replace NUMBER with NUMERIC in your 2nd create statement.
CREATE TABLE deposits
(
deposit NUMERIC(8),
whopaid VARCHAR(25),
amount DECIMAL(6,2),
remarks VARCHAR(20)
)
SQLFiddle example
See MySQL String data types and MySQL numeric data types
check is a reserved work, that's why you have this error
you need to put quotes around it
CHECK is a reserved keyword in mysql. If you choose a different name it should work fine.
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
Related
got this error message "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 'INSERT INTO 'employees1'"
Write your MySQL query statement below
create table employees1 (emp_id INT(6) UNSIGNED, event_day DATE NOT NULL, in_time int NOT NULL,
out_time int NOT NULL )
INSERT INTO 'employees1' ('emp_id', 'event_day', 'in_time', 'out_time')
values (1,20201128,4,32),
(1,20201128,55,200)
Please use a semicolon at the end of a statement, and use backticks for table names and column names. Those are fundamental rules which can be easily learned should you decide to spend a little more efforts.
create table employees1 (emp_id INT(6) UNSIGNED, event_day DATE NOT NULL, in_time int NOT NULL,
out_time int NOT NULL );
INSERT INTO `employees1` (`emp_id`, `event_day`, `in_time`, `out_time`)
values (1,20201128,4,32),
(1,20201128,55,200);
Good Day!
what is the proper syntax query in MySQL? I'm getting error in mysql during execution (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 'EmpCode AS CONCAT('EMP' , RIGHT(Concat('0000', CONVERT(EmpId, ' at line 3)
CREATE TABLE tbEmployee
(
EmpId INT NOT NULL, PRIMARY KEY,
EmpCode AS CONCAT('EMP' , RIGHT(Concat('0000', CONVERT(EmpId, CHAR(5))),5)) PERSISTED,
EmployeeName VARCHAR(50),
Age INT,
Gender VARCHAR(10)
)
MySQL generated columns are either VIRTUAL (the default) or STORED, the latter corresponding to SQL Server's persisted. Try this version:
CREATE TABLE tbEmployee (
EmpId INT NOT NULL PRIMARY KEY,
EmpCode VARCHAR(50) AS (CONCAT('EMP', LPAD(EmpId, 5, '0'))) STORED,
EmployeeName VARCHAR(50),
Age INT,
Gender VARCHAR(10)
);
Note also that MySQL is a bit more lax with regards to casting numeric columns to text. Also, we can use MySQL's LPAD function to left pad the employee ID with zeroes, to a width of 5 digits.
I tried to create a brand new table with codes:
MySQL [distributor]> create table order
-> (
-> order_num integer not null,
-> order_date datetime not null,
-> cust_id chat(10) not null
-> );
It generates errors:
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 'order
(
order_num integer not null,
order_date datetime not null,
cust_id chat(' at line 1
I have checked multiple times to ensure there no problems in my codes since SQL is case-insensitive.
What's the bug with my code?
There are two issues with your query: Firstly, order is a MySQL reserved word. Secondly, you have chat which should be char. Try this instead (renaming table to orders):
CREATE TABLE orders
(
order_num integer not null,
order_date datetime not null,
cust_id char(10)
);
order it's a reserved word and put char instead of chat. You can name the table orders
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 am using the mysql admin GUI tool to create a table. Here is the query language that results in an error:
CREATE TABLE `environment`.`moisture` (
`city_id` INT,
`date_holding` VARCHAR,
`time_holding` VARCHAR,
`open` REAL,
`high` REAL,
`low` REAL,
`close` REAL,
)
CHARACTER SET utf8;
My date and time are not of the format mysql likes so I selected VARCHAR as the type for those columns and referred to them as holding columns until I can run queries to make the necessary conversions.
When I try to execute this via the GUI I get the following:
Error executing SQL commands to create 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 'NOT NULL,
`time_holding` VARCHAR NOT NULL,
`open` REAL NOT NULL,
`high` RE' at line 3 (error 1064)
Any idea why I am getting this? I have checked to see if I am using any reserved words but that does not seem to be the case.
Your help would be greatly appreciated.
The first error you have is due to that VARCHAR fields need a length like this: VARCHAR(30).
The second error (you'll get if you fix the 2 varchars) is the comma before the last parenthesis.
CREATE TABLE `environment`.`moisture` (
`city_id` INT,
`date_holding` VARCHAR(30), --or whatever length you want
`time_holding` VARCHAR(20), --same
`open` REAL,
`high` REAL,
`low` REAL,
`close` REAL --- no comma here
)
CHARACTER SET utf8;
Side note: You do know that MySQL has specific types to handle dates and times, don't you? So you could have:
CREATE TABLE `environment`.`moisture` (
`city_id` INT,
`date_holding` date,
`time_holding` time,
...