· 8 years ago · Nov 26, 2017, 11:12 PM
1-- Create a Database
2CREATE DATABASE IF NOT EXISTS mydatabase;
3
4-- Switch to using that database
5-- (so that all tables are created in this and not the master db)
6USE mydatabase;
7
8-- Create a Table
9CREATE TABLE IF NOT EXISTS mytable
10(
11 id int PRIMARY KEY AUTO_INCREMENT,
12 email varchar(50) NOT NULL UNIQUE,
13 firstname varchar(50),
14 lastname varchar(50)
15);
16
17-- See stuff in the table you created
18-- (You'll see nothing since this is empty at this point)
19SELECT * FROM mytable;
20
21-- Add some data to the table
22INSERT INTO mytable (email, firstname, lastname)
23VALUES
24 ('jane@doe.com', 'Jane', 'Doe'),
25 ('john@doe.com', 'John', 'Doe'),
26 ('jenny@doe.com', 'Jenny', 'Doe'),
27 ('penny@doe.com', 'Penny', 'Doe')
28;
29
30-- See the data in the table
31SELECT * FROM mytable;