0

im trying to create a table using mysql and phpmyadmin with the w

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

but i keep recieving an 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_INCREMEN' at line 3

i was wondering if anybody could help me

NOTE - i have tried putting '' around the database name and id, unique_id and so on.

Anandhu Nadesh
  • 672
  • 2
  • 11
  • 20
Jared
  • 25
  • 3
  • Probably a missing semi colon before `USE` – M Khalid Junaid Dec 07 '17 at 14:10
  • 1
    Try using ticks around the table name instead of quotes. There is a difference in 'users' and `users`. You'll find ticks at the top left of your key board, same key as ~. – Sari Rahal Dec 07 '17 at 14:13
  • Possible duplicate of [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – aynber Dec 07 '17 at 14:14

2 Answers2

1

Try this:

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

Separate three statements with ;

Joe Taras
  • 15,166
  • 7
  • 42
  • 55
0

Try this:

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

);

It should work like this:

mysql-sql> use android_api;
Query OK, 0 rows affected (0.00 sec)
mysql-sql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| android_api        |
| devel              |
[...]
+--------------------+

Can verify you created the table

mysql-sql> show tables;
+-----------------------+  
| Tables_in_android_api |
+-----------------------+
| users                 |
+-----------------------+
1 row in set (0.00 sec)
DDeMartini
  • 339
  • 1
  • 6