I am trying to run this query in my database:
CREATE TABLE users(
user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR NOT NULL,
userpass VARCHAR NOT NULL,
first_name VARCHAR NOT NULL,
last_name VARCHAR NOT NULL,
email VARCHAR NOT NULL,
address VARCHAR NOT NULL,
phone BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(user_id)
)
MySQL returns this error:
#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 'NOT NULL,
userpass VARCHAR NOT NULL,
first_name VARCHAR NOT NULL,
' at line 3
I cant figure out what is wrong with the code...
You need to specify size for VARCHAR columns:
CREATE TABLE users( user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(100) NOT NULL,
userpass VARCHAR(100) NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
address VARCHAR(100) NOT NULL,
phone BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(user_id) );
SqlFiddleDemo
Storing phone number as BIGINT is not best idea. Consider normal string instead.
Related
CREATE TABLE `chuchutvlogin`. (
`id` INT NOT NULL AUTO_INCREMENT ,
`username` VARCHAR(20) NOT NULL ,
`gender` CHAR(1) NOT NULL ,
`email` VARCHAR(50) NOT NULL ,
`password` VARCHAR(20) NOT NULL ,
`number` BIGINT(10) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
what's issue?
i was creating a login databse and error #1064 came syntax error in localhost phpmyadmnin
Fix syntax error in your query, remove dot char after table name:
CREATE TABLE chuchutvlogin (
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(20) NOT NULL,
gender CHAR(1) NOT NULL,
email VARCHAR(50) NOT NULL,
password VARCHAR(20) NOT NULL,
number BIGINT(10) NOT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB;
dbfiddle
How to use if not exists in MySQL database.
create schema if not exists appkasir;
use appkasir;
create table if not exists admin (
id int(11) not null auto_increment,
nama varchar(20) not null,
no_telp varchar(20) null,
alamat varchar(50) null,
email varchar(50) null,
primary key (id)
);
You give no congret error message. I think it's not an error of if exists but maybe of the primary key.
Look at MySQL reference.
Try:
create schema if not exists appkasir;
use appkasir;
create table if not exists admin (
id int(11) not null auto_increment primary key,
nama varchar(20) not null,
no_telp varchar(20) null,
alamat varchar(50) null,
email varchar(50) null
);
SQLSTATE[42000]: Syntax error or access violation: 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 '1 NOT NULL,
default_value VARCHAR(255), is_encrypted TINYINT(1) NOT NULL, is_met'
at line 1.
Failing Query:
"CREATE TABLE ohrm_display_field (report_group_id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL, label VARCHAR(255) NOT NULL, field_alias
VARCHAR(255), is_sortable VARCHAR(10) NOT NULL, sort_order
VARCHAR(255), sort_field VARCHAR(255), element_type VARCHAR(255) NOT
NULL, element_property TEXT NOT NULL, width VARCHAR(255) NOT NULL,
is_exportable VARCHAR(10), text_alignment_style VARCHAR(20),
is_value_list TINYINT(1) NOT NULL, display_field_group_id 1 NOT NULL,
default_value VARCHAR(255), is_encrypted TINYINT(1) NOT NULL, is_meta
TINYINT(1) DEFAULT '0' NOT NULL, display_field_id BIGINT
AUTO_INCREMENT, PRIMARY KEY(display_field_id)) ENGINE = INNODB"
[Solved]
Next Error:
SQLSTATE[42000]: Syntax error or access violation: 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 ' PRIMARY
KEY(id)) ENGINE = INNODB' at line 1.
Failing Query:
"CREATE TABLE ohrm_job_interview_attachment (id BIGINT, interview_id BIGINT, file_name VARCHAR(255), file_type VARCHAR(255), file_size BIGINT, file_content LONGBLOB, attachment_type INT, comment , PRIMARY KEY(id)) ENGINE = INNODB"
Can anyone suggest what's the error in the indicated query?
Any effective guidance will be highly appreciated.
The issue is here
display_field_group_id 1 NOT NULL,
You need to assign some data type if its tinyint then the following should work
CREATE TABLE ohrm_display_field
(
report_group_id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL,
label VARCHAR(255) NOT NULL,
field_alias VARCHAR(255),
is_sortable VARCHAR(10) NOT NULL,
sort_order VARCHAR(255),
sort_field VARCHAR(255),
element_type VARCHAR(255) NOT NULL,
element_property TEXT NOT NULL,
width VARCHAR(255) NOT NULL,
is_exportable VARCHAR(10),
text_alignment_style VARCHAR(20),
is_value_list TINYINT(1) NOT NULL,
display_field_group_id TINYINT(1) NOT NULL,
default_value VARCHAR(255),
is_encrypted TINYINT(1) NOT NULL,
is_meta TINYINT(1) DEFAULT '0' NOT NULL,
display_field_id BIGINT AUTO_INCREMENT,
PRIMARY KEY(display_field_id)
) ENGINE = INNODB
Getting 1064 mysql error in this code....
CREATE TABLE User(
user_id int(10),
first_name varchar2(30) NOT NULL,
last_name varchar2(30) NOT NULL,
user_name varchar2(20),
email_id varchar2(50),
password varchar2(20) NOT NULL,
contact_no varchar2(15),
highest_degree varchar2(30) NOT NULL,
photo longblob,
STATE varchar2(25),
score int NOT NULL,
institute_name varchar2(50),
PRIMARY KEY(user_id),
UNIQUE (user_name),
UNIQUE(email_id)) ENGINE=InnoDB;
Can't figure out how to eliminate it.. Can anyone please help?
No varchar2 in mysql use varchar
This works
create table User(
user_id int(10),
first_name varchar(30) NOT NULL,
last_name varchar(30) NOT NULL,
user_name varchar(20),
email_id varchar(50),
password varchar(20) NOT NULL,
contact_no varchar(15),
highest_degree varchar(30) NOT NULL,
photo longblob,
state varchar(25),
score int NOT NULL,
institute_name varchar(50),
PRIMARY KEY(user_id),
UNIQUE (user_name),
UNIQUE(email_id)
) ENGINE=InnoDB;
My server is on hostgator running on a linux centOS.
I'm simply trying to create a table within my database and I figured out how to get the table to get created. Although when I add the AUTO_INCREMENT setting the code doesn't execute and the table isn't created.
Why would this be and how can I correct it?
Here is my code:
$members2_table = "CREATE TABLE ninja08_codin.members2(
id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(40),
last_name VARCHAR(40) NOT NULL,
email VARCHAR(64) NOT NULL,
date_joined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
cred VARCHAR(10) NOT NULL)";
To use AUTO_INCREMENT you may have to assign the column as a primary key:
$members2_table = "CREATE TABLE ninja08_codin.members2(
id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(40),
last_name VARCHAR(40) NOT NULL,
email VARCHAR(64) NOT NULL,
date_joined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
cred VARCHAR(10) NOT NULL,
PRIMARY KEY (id))";
Your query will give error
there can be only one auto column and it must be defines as a key, so add primary key to id field
$members2_table = "CREATE TABLE ninja08_codin.members2(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(40),
last_name VARCHAR(40) NOT NULL,
email VARCHAR(64) NOT NULL,
date_joined TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
cred VARCHAR(10) NOT NULL)";