CREATE TABLE `db`.`Complete` (
`CompleteId` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`HoursTaken` DOUBLE( 5 ) NOT NULL ,
`DateFinished` DATETIME NOT NULL
) ENGINE = MYISAM
I am trying to create this simple table, however, I get an error. The above code is the code generated by a UI for a MySql database.
I get this 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 ') NOT NULL ,
`DateFinished` DATETIME NOT NULL
) ENGINE = MYISAM' at line 4
I am not sure what to change.
You need to add the precision to the DOUBLE datatype, it should be DOUBLE(5,n) I think.
I solved this by using float instead of double, this was the generated code:
CREATE TABLE `db`.`Complete` (
`CompleteId` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`HoursTaken` FLOAT NOT NULL ,
`DateFinished` DATETIME NOT NULL
) ENGINE = MYISAM
Related
Im trying to creat a database for storing Photos in my sqli with the following code:
CREATE TABLE `photos`.`images` (
`id` INT NOT NULL AUTO_INCREMENT ,
`file` BLOB BINARY NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
so when i try to save it i got the following error . The error is the this :
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 'BINARY NOT NULL , PRIMARY KEY (id)) ENGINE = InnoDB' at line 1
does someone whats the error about !
Just remove the BINARY keyword:
CREATE TABLE `photos.images` ( `id` INT NOT NULL AUTO_INCREMENT , `file` BLOB NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
so i'm having an issue using sysdate function as my default data value in MySQL. my code to create the table is as follows:
CREATE TABLE orders
(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
odr_date DATE DEFAULT sysdate() NOT NULL
);
i get the error
[42000][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 'sysdate()
)' at line 4
instead of sysdate() try CURRENT_TIMESTAMP for mysql
reference: Type date default sysdate in Mysql
CREATE TABLE orders
(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
odr_date DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE TABLE `oc_appconfig` (
`appid` VARCHAR( 32 ) DEFAULT '' NOT NULL ,
`configkey` VARCHAR( 64 ) DEFAULT '' NOT NULL ,
`configvalue` CLOB DEFAULT NULL ,
PRIMARY KEY ( `appid` , `configkey` )
);
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 'CLOB DEFAULT NULL, PRIMARY KEY(appid, configkey))' at line 1
How i can fix this error. Pls Guys. I need my NextCloud!
MySQL has no CLOB data type. Use TEXT.
See the doc
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.
SQL query:
CREATE TABLE `comment_threads` (
`comment_id` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0',
`updated` TIMESTAMP NOT NULL ,
`timestamp` TIMESTAMP NOT NULL ,
) ENGINE = MYISAM ;
This is an old file that I'm trying to run on HostGator through phpMyAdmin. I get an error that says:
MySQL said: #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 ') ENGINE=MyISAM' at line 5
UPDATE:
If I change the statement to this, I still get an error:
CREATE TABLE comment_threads (
comment_id INT( 11 ) UNSIGNED NOT NULL DEFAULT '0',
updated TIMESTAMP( 14 ) NOT NULL ,
timestamp TIMESTAMP NOT NULL
PRIMARY KEY ( comment_id ) )
ENGINE = MYISAM ;
I get the 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 '( 14 ) NOT NULL ,
timestamp TIMESTAMP NOT NULL
PRIMARY KEY ( comment_id ) )
ENGI' at line 3
Your MySQL query is incorrect. Correcting it to this works.
CREATE TABLE `comment_threads` (
`comment_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`updated` TIMESTAMP NOT NULL ,
`timestamp` TIMESTAMP NOT NULL
) ENGINE=MyISAM;
To run this in phpMyAdmin, you can use the in-built table creator or enter the corrected SQL statement in the SQL query window.
Note that I removed the comma after the last TIMESTAMP NOT NULL line (immediately before the ending ).
UPDATE:
The second statement you posted corrects to this:
CREATE TABLE `comment_threads` (
`comment_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`updated` TIMESTAMP NOT NULL ,
`timestamp` TIMESTAMP NOT NULL,
PRIMARY KEY(`comment_id`)
) ENGINE=MyISAM;
Here are the problems you introduced in your second CREATE TABLE statement:
TIMESTAMP( 14 ) should just be TIMESTAMP (per the documentation)
You need a comma after the line TIMESTAMP NOT NULL line. The comma is necessary now because unlike in the first example, you're separated two parts of the statement: the TIMESTAMP NOT NULL line and the PRIMARY KEY declaration.
If you want more information on simple methods for debugging SQL statements, I strongly suggest you look at my answer to this question (see the section titled A bit more information on how to methodically fix errors like this).
Make sure that when you change a CREATE TABLE statement, or any piece of code, that you make changes in small enough increments that you're only "breaking at most one thing at a time." In the case of your second CREATE TABLE statement, there was no reason to change the first TIMESTAMP declaration, and doing so broke the code. That line was working; no need to change it.