I am trying to create a table using this command in MySQL:
CREATE TABLE tutorial_info(
tutorial_id INT NOT_NULL AUTO_INCREMENT PRIMARY KEY,
tutorial_title VARCHAR(100) NOT_NULL,
tutorial_author VARCHAR(100) NOT_NULL,
submission_date TIMESTAMP
);
I just cut and paste the code into the terminal but I am getting 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 'NOT_NULL AUTO_INCREMENT PRIMARY KEY, tutorial_title VARCHAR(100) NOT_NULL, ' at line 1
Not sure what is going on here. Could someone give me a pointer to what I might be doing wrong here? Thanks
Change NOT_NULL to NOT NULL as:
CREATE TABLE tutorial_info(
tutorial_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
tutorial_title VARCHAR(100) NOT NULL,
tutorial_author VARCHAR(100) NOT NULL,
submission_date TIMESTAMP
);
Use not null without _
CREATE TABLE tutorial_info(
tutorial_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
tutorial_title VARCHAR(100) NOT NULL,
tutorial_author VARCHAR(100) NOT NULL,
submission_date TIMESTAMP
);
Related
I can't find and error, when I try to execute:
create database android_api
use android_api
create table users(
id int(11) primary key auto_increment,
unique_id varchar(23) not null unique,
name varchar(50) not null,
email varchar(100) not null unique,
encrypted_password varchar(80) not null,
salt varchar(10) not null,
created_at datetime,
updated_at datetime null
);
I get and 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 '
use android_api
create table users(
id int(11) primary key auto_increme' at line 3"
just separate your code with ';'
create database android_api;
use android_api;
create table users(
id int(11) primary key auto_increment,
unique_id varchar(23) not null unique,
name varchar(50) not null,
email varchar(100) not null unique,
encrypted_password varchar(80) not null,
salt varchar(10) not null,
created_at datetime,
updated_at datetime null
);
The answer is that you can't do it.
Do those processes in 3 different queries.
With this code:
create table jogadores(
id INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
nome varchar NOT NULL,
idade int NOT NULL UNSIGNED,
nacionalidade varchar NOT NULL
)
I keep getting this error:
)
Error report -
SQL Error: 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,
idade int NOT NULL UNSIGNED,
nacionalidade varchar NOT NULL
)' at line 3.
Also, I get the red underline under the "T" and the "(" in "INT(10)".
varchar() should have a length:
create table jogadores (
id INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
nome varchar(255) NOT NULL,
idade int UNSIGNED NOT NULL,
nacionalidade varchar(255) NOT NULL
);
And UNSIGNED needs to go immediately after the numeric declaration, not after NOT NULL. See here.
You need to specify the length of the varchar i.e. varchar(100).
I want to make a table in phpmyadmin and I am using SQL command for that
CREATE TABLE userdetail(
detailid INT(255) UNSIGNED AUTO_INCREMENT PRIMARY,
name varchar(255) NOT NULL,
address text,
phone varchar(13) NOT NULL,
email_id varchar(255),
userId int(20) NOT NULL,
reg_date TIMESTAMP
)
I am getting this 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 '
name varchar(255) NOT NULL,
address text,
phone varchar(13) NOT ' at line 2
It should be like this
CREATE TABLE userdetail(
detailid INT(255) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
address text,
phone varchar(13) NOT NULL,
email_id varchar(255),
userId int(20) NOT NULL,
reg_date TIMESTAMP);
You are missing KEY after PRIMARY:
CREATE TABLE userdetail (
detailid INT(255) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
address text,
phone varchar(13) NOT NULL,
email_id varchar(255),
userId int(20) NOT NULL,
reg_date TIMESTAMP
)
Note that int(255) really doesn't make sense. Are you familiar with the integer data types and what the value in parentheses means? You can review the documentation here.
Can some one help me in correcting the syntax according to MySQL 5.7?
Table :
CREATE TABLE Employee(
EMPID INT NOT NULL AUTO_INCREMENT,
EMPNAME VARCHAR(20) NOT NULL,
EMPAGE INT NOT NULL,
SALARY BIGINT NOT NULL,
ADDRESS VARCHAR(20) NOT NULL
PRIMARY KEY (ID)
);
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 '(ID)
You forgot comma at the end of this line:
ADDRESS VARCHAR(20) NOT NULL
You dont have a column named ID, you may want EMPID?
Replace
ADDRESS VARCHAR(20) NOT NULL
By
ADDRESS VARCHAR(20) NOT NULL,
There are two problems here:
A primary key clause is it's own clause, and needs to be separated from the previous column definition by a comma.
You don't have an id column - your primary key should (probably) be empid:
CREATE TABLE Employee(
EMPID INT NOT NULL AUTO_INCREMENT,
EMPNAME VARCHAR(20) NOT NULL,
EMPAGE INT NOT NULL,
SALARY BIGINT NOT NULL,
ADDRESS VARCHAR(20) NOT NULL,
PRIMARY KEY (EMPID)
);
I guess this is what you are looking for:
CREATE TABLE Employee(
EMPID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
EMPNAME VARCHAR(20) NOT NULL,
EMPAGE INT NOT NULL,
SALARY BIGINT NOT NULL,
ADDRESS VARCHAR(20) NOT NULL
);
Perhaps I'm just too used to Postgres but why am I getting this 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 '{ id int not null AUTO_INCREMENT, email varchar(100) not null,
primary key(id' at line 1
when I run this?
create table `users`{
id int not null AUTO_INCREMENT,
email varchar(100) not null,
primary key(id)
};
Use parenthesis (normal brackets) () not braces:
create table `users` (
id int not null AUTO_INCREMENT,
email varchar(100) not null,
primary key(id)
);
the correct syntax is :
CREATE TABLE users (
id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(100) NOT NULL,
PRIMARY KEY(id)
);
check it out here for your version:
https://dev.mysql.com/doc/refman/4.1/en/creating-tables.html