Getting syntax error on sql database create table - mysql

So i'm trying to create a table using MySQL Workbench like this:
DROP TABLE IF EXISTS document_categories;
CREATE TABLE document_categories (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL DEFAULT '',
created_at timestamp NOT NULL DEFAULT current_timestamp(),
updated_at timestamp NULL DEFAULT current_timestamp(),
deleted_at datetime DEFAULT NULL,
PRIMARY KEY (id)
);
But im getting this error:
11:54:19 ​ CREATE TABLE document_categories ( id int(10) unsigned NOT NULL AUTO_INCREMENT, name varchar(64) NOT NULL DEFAULT '', created_at timestamp NOT NULL DEFAULT current_timestamp(), updated_at timestamp NULL DEFAULT current_timestamp(), deleted_at datetime DEFAULT NULL, PRIMARY KEY (id) ) Error Code: 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 '​ CREATE TABLE document_categories ( id int(10) unsigned NOT NULL AUTO_IN...' at line 1 0.000 sec
I don't really see what the problem is here. Also I'm using MariaDB as the database

Related

Mysql automated date field, syntax errors

I'm trying to create a mysql table which contains two fields that are automatically given the current date when data is first put into them
CREATE TABLE IF NOT EXISTS `database`.`characters` (
`character_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`ckey` VARCHAR(30) NOT NULL,
`character_name` VARCHAR(26) NOT NULL,
`birth` DATE NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_seen` DATE NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`character_id`),
UNIQUE INDEX `character_id_UNIQUE` (`character_id` ASC) VISIBLE)
this is not working, i get invalid default value error, which is progress
Everything else i've tried throws error 1064, sql syntax
In place of current timestamp I have tried...
GET_DATE()
GET_DATE
GETDATE
CURDATE
CURDATE()
CURRENT_DATE
CURRENT_DATE()
All of these are throwing the same syntax error, there is no error if i remove the default value.
I am almost entirely clueless about database code, this is a real newbie project, any help would be appreciated
Use datetime instead of date.
CREATE TABLE IF NOT EXISTS `characters` (
`character_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`ckey` VARCHAR(30) NOT NULL,
`character_name` VARCHAR(26) NOT NULL,
`birth` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_seen` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`character_id`),
UNIQUE INDEX `character_id_UNIQUE` (`character_id` ASC) VISIBLE)

MYSQL Error 1064 in DateTime and TimeStamp

Good day, I'm creating some tables on my database and when i try to save, it throws 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 '0) NOT NULL , date_registered DATETIME NOT NULL , last_login TIMESTAMP NOT' at line 1
This sort of error has been debugged here on Stackoverflow before and the solution was to remove the length from the TIMESTAMP column. Other solutions asked the advised that quotes should be removed from column identifiers or ticks should be used instead. Unfortunately, my DATETIME and TIMESTAMP columns do not have lengths and my column identifiers have ticks around them.
Here's what my SQL statement looks like. Can someone please assist?
CREATE TABLE `inventoryman_db`.`users`
( `id` INT NOT NULL AUTO_INCREMENT ,
`full_name` VARCHAR(255) NOT NULL ,
`email` VARCHAR(255) NOT NULL ,
`password` VARCHAR(300) NOT NULL ,
`usertype` ENUM(0) NOT NULL ,
`date_registered` DATETIME NOT NULL ,
`last_login` TIMESTAMP NOT NULL ,
`notes` VARCHAR(255) NOT NULL COMMENT 'For verification and other purposes, we will store a random key here' ,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
try this, you only need to add quotes in enum('0') as enum consider as string with indexing his arrays.
CREATE TABLE `percept`.`users1` ( `id` INT NOT NULL AUTO_INCREMENT ,
`full_name` VARCHAR(255) NOT NULL , `email` VARCHAR(255) NOT NULL ,
`password` VARCHAR(300) NOT NULL ,
`usertype` ENUM('0') NOT NULL ,
`date_registered` DATETIME NOT NULL ,
`last_login` TIMESTAMP NOT NULL ,
`notes` VARCHAR(255) NOT NULL COMMENT 'For verification and other purposes, we will store a random key here' ,
PRIMARY KEY (`id`)) ENGINE = InnoDB `
just add quotes in enum

Problems with sql MariaDB (1064)

I can't solve this error showing on my database:
check the manual that corresponds to your MariaDB server version for
the right syntax to use near 'CREATE TABLE tf_links' at line 12
My SQL file code is:
CREATE TABLE tf_cookies (
cid int(10) NOT NULL auto_increment,
uid int(10) NOT NULL default '0',
host VARCHAR(255) default NULL,
data VARCHAR(255) default NULL,
PRIMARY KEY (cid)
) ENGINE=MyISAM;
--
-- tf_links
--
CREATE TABLE tf_links (
lid int(10) NOT NULL auto_increment,
url VARCHAR(255) NOT NULL default '',
sitename VARCHAR(255) NOT NULL default 'Old Link',
sort_order TINYINT(3) UNSIGNED default '0',
PRIMARY KEY (lid)
) ENGINE=MyISAM;

making a Mysql table and I keep getting the same syntax error

Im very new to mysql and I keep getting the same error whenever i try to make a table
CREATE TABLE tasks {
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT PRIMARY KEY ,
description VARCHAR(64) NOT NULL,
completed TINYINT(2) NOT NULL DEFAULT 0,
created DATETIME NOT NULL DEFAULT NOW(),
last_updated DATETIME NOT NULL DEFAULT NOW() ON UPDATE NOW()
};
I wanted it to make a table but instead I got:
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 '{
id INT NOT NULL PRIMA' at line 1
You have a syntax error. CREATE TABLE uses parentheses not braces.
CREATE TABLE foo(col1 int, col2 varchar(25), col3 timestamp);
Here is the right syntax:
CREATE TABLE tasks (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, description VARCHAR(64) NOT NULL, completed TINYINT(2) NOT NULL DEFAULT 0, created DATETIME NOT NULL DEFAULT NOW(), last_updated DATETIME NOT NULL DEFAULT NOW() ON UPDATE NOW())

I keep getting an error when trying to make a table in phpmyadmin

when I was trying to run this code:
USE user;
CREATE TABLE IF NOT EXISTS 'posts' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'body' text NOT NULL,
'date_added' date NOT NULL,
'added_by' varchar(255) NOT NULL,
'user_posted_to' varchar(255) NOT NULL,
PRIMARY KEY ('id')
)ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
It gave me 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 ''posts' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'body' text NOT NULL,
'dat' at line 1
how do I solve it? By the way, I already selected a database? Any help would be appreciated.
Get rid of all the "'" marks.
CREATE TABLE IF NOT EXISTS posts (
id int(11) NOT NULL AUTO_INCREMENT,
body text NOT NULL,
date_added date NOT NULL,
added_by varchar(255) NOT NULL,
user_posted_to varchar(255) NOT NULL,
PRIMARY KEY (id)
)ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
Here is a fiddle with a working creation.