1

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
);
1
  • Um.. here - updated_at datetime null ? you don't need to give null there Commented Dec 4, 2016 at 13:31

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

9 Comments

hmm now I have error A symbol name was expected! near name unexpected beginning of statement near 50 Unrecognized statement type neae not null name varchar(50) not null,
are you using mysql? which version? how exactly you run these queries?
SQL it's phpMyAdmin php ver 5.5
and you still didn't answer what version of mysql you are using
My hosting using MariaDB version 10
|
1

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.

1 Comment

Ok, definitely as a beginner, I can't see why and where's this error coming from. But this solved!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.