I am trying to create a database for my login/signup forms. I creted this database using SQL. However, when importing it in phpmyadmin it says "Import has been successfully finished, 5 queries executed."
then the error:
Error
SQL query:
CREATE TABLE if not exists LoginTable(
name varchar(100) not null,
email varchar(100) not null default "",
password varchar(50) not null default "",
age integer(50) not null,
primary key ('email', 'password')
)
MySQL said: Documentation
#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 ''email', 'password')
)' at line 7
this is my sql code:
drop database if exists loginInfo;
create database if not exists loginInfo;
use loginInfo;
drop table if exists LoginTable;
CREATE TABLE if not exists LoginTable(
name varchar(100) not null,
email varchar(100) not null,
password varchar(50) not null,
age integer(50) not null,
primary key ('email', 'password')
);
Remove Single quotes in email, password.
While defining primary key you don't need to add quotes.
drop database if exists loginInfo;
create database if not exists loginInfo;
use loginInfo;
drop table if exists LoginTable;
CREATE TABLE if not exists LoginTable(
name varchar(100) not null,
email varchar(100) not null,
password varchar(50) not null,
age integer(50) not null,
primary key (email, password)
);
Related
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 1 year ago.
I'm trying to create a table in my schema (mydb) called employee, but whenever I try running the script to create the table I get error #1064.
I'm new to SQL so I was looking at examples on how to create tables and went off those examples to create my own until I bumped into this error. Could anyone explain why I am getting this error message please?
MySQL Workbench Community 8.0 Version 8.0.26:
CREATE TABLE 'mydb'.'employee'
(
'emp#' INT PRIMARY KEY,
'firstname' VARCHAR(20) NOT NULL,
'surname' VARCHAR(20) NOT NULL,
'salary' INT default 0,
'city' VARCHAR(20),
UNIQUE(firstname, surname)
);
Error:
Error Code: 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 ''mydb'.'employee' ( 'emp#' INT Primary key, 'firstname' VARCHAR(20) NOT NULL, 's' at line 1
Your issue is the because you are adding ' single quotes in your CREATE TABLE statement, you need to do it like this:
CREATE TABLE mydb.employee
(
emp INT PRIMARY KEY,
firstname VARCHAR(20) NOT NULL,
surname VARCHAR(20) NOT NULL,
salary INT default 0,
city VARCHAR(20),
UNIQUE(firstname, surname)
);
If you need the quotes in Mysql you need to use the curly single quote like this:
CREATE TABLE `mydb`.`employee`
(
`emp_id` INT PRIMARY KEY,
`firstname` VARCHAR(20) NOT NULL,
`surname` VARCHAR(20) NOT NULL,
`salary` INT default 0,
`city` VARCHAR(20),
UNIQUE(firstname, surname)
);
Also instead of using #, use _id or no you can check the following reference about MySQL Naming Rules
I want to create a script written by someone else in order to create tables and entries etc. in my own database.
The command I want to run is:
mysql -h localhost -u root shop < C:/myInstance/web/website/sql/myWeb.sql
I got this line by reading a couple of posts on SO. Yet I got these error message:
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 'mysql -h localhost -u root shop < C:/myInstance/web/website/sql/myWeb.sql' at line 1
This suggests that there is clearly a syntax error, at this point I'm not even sure if the error is within my command of that file. Can you help me? I'm quite new to this, here is that file:
create table store_product
(
id bigint auto_increment primary key,
name varchar(32) not null,
description varchar(500),
imageSrc varchar(500),
price double not null
);
create table store_user
(
id bigint auto_increment primary key,
name varchar(32) unique not null,
password varchar(16) not null,
address varchar(100),
postCode varchar(10),
email varchar(50),
homePhone varchar(32),
cellPhone varchar(32),
officePhone varchar(32),
type varchar(20),
workNo varchar(20)
);
insert into store_user values(1,'throne212','123',' XXX ','621000','throne212#xxx.com','123456789','123456789','123456789','common',null);
insert into store_user values(2,'admin','123','','','admin#xxx.com','','','','admin','001');
create table store_order(
id bigint primary key,
orderNum varchar(17) unique not null,
status integer not null,
user_id bigint references store_user(id),
cost double(10,2)
);
create table store_order_item(
id bigint auto_increment primary key,
amount integer not null,
product_id bigint references store_product(id),
order_id bigint references store_order(id)
);
I am trying to create database android_api and table users but I am getting error
#1064 - Something is wrong in your syntax near 'use android_api
create table 'users'(
id int(11) NOT NULL primary KEY AU' w linii 3
Here is the code
create database android_api
use android_api
create table users(
id int(11) NOT NULL 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
);
You should separate each SQL statement with ;, otherwise your syntax is incorrect.
Here is the correct syntax:
create database android_api;
use android_api;
create table users(
id int(11) NOT NULL 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
);
In your code what you did was actually:
create database android_api use android_api
(Which is not a valid CREATE statement).
Actually, the accepted answer is enough. This is a very small idea to share after running into the same problem as you report it, but in a beginner's tutorial Load PostgreSQL Sample Database in an SQL Shell.
In general, if you have the reported error in an SQL shell, and if you are not sure whether you have typed ; at the end of the last line, just type ; as a new command and press Enter to be sure that you type your next command in LINE 1 and not in LINE 2.
Without this "trick", some stupidity like this can happen:
postgres=# CREATE DATABASE dvdrental
postgres-# show databases
postgres-# create database dvdrental;
ERROR: syntax error at or near »show«
LINE 2: show databases
^
postgres=# create database dvdrental
postgres-# CREATE DATABASE dvdrental;
ERROR: syntax error at or near »CREATE«
LINE 2: CREATE DATABASE dvdrental;
^
postgres=# CREATE DATABASE dvdrental;
CREATE DATABASE
Finally working, as can be seen by the output CREATE DATABASE.
I have this #1007 error with my SQL code. When I try to import into my database it gives me this #1007 error. The data base is called company. I'm new to SQL and it would be good if someone could help me out. Thanks
CREATE DATABASE company;
CREATE TABLE login(
id int(10) NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
)
It looks like the database "company" may already exist. If you look at the link provided by #Marc B, the error "#1007" corresponds to:
"Error: 1007 SQLSTATE: HY000 (ER_DB_CREATE_EXISTS)
Message: Can't create database '%s'; database exists
An attempt to create a database failed because the database already exists.
Drop the database first if you really want to replace an existing database, or add an IF NOT EXISTS clause to the CREATE DATABASE statement if to retain an existing database without having the statement produce an error."
Check your schema to make sure that you don't already have a database called "company" created.
Perhaps you are only trying to create the table "login", whereas you would simply need the code:
CREATE TABLE login(
id int(10) NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
)
making sure you create this table in the already existing "company" database.
You are trying to create a database that has already been created.
Staring at your two commands, you could do CREATE TABLE IF NOT EXISTS
you also need to set default database before creating the table
CREATE DATABASE IF NOT EXISTS company;
USE company
CREATE TABLE login (
id int NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
);
or you could put the DB name before the table name
CREATE DATABASE IF NOT EXISTS company;
CREATE TABLE company.login (
id int NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (id)
);
I am new to MySQL commands. please, I tried creating a table using the MAMP MySQL editor and I got an error #1046 No database selected..Below is the simple code:
[code]
CREATE TABLE EMPLOYEE_TABLE AS:
(SSN NUMBER(9) NOT NULL,
LAST_NAME VARCHAR2(20) NOT NULL,
FIRST_NAME VARCHAR2(20) NOT NULL,
MIDDLE_NAME VARCHAR2(20) NOT NULL,
ST ADDRESS VARCHARS2(20) NOT NULL,
CITY CHAR(20) NOT NULL,
STATE CHAR(2) NOT NULL,
ZIP NUMBER(4) NOT NULL,
DATE_HIRED DATE)
STORAGE(INITIAL 3K,
NEXT 1K)
[/code]
You have to select the database where you want to insert the table, there are to ways to do it :
Selecting the default database : USE databasename;
Specifying database name before the table in the CREATE TABLE statement : CREATE TABLE DATABASENAME.EMPLOYEE_TABLE ...
Where databasename is the name of your database.