Last active
November 25, 2017 09:34
-
-
Save aamnah/64779b1c9ebdb349f84f44911179a85e to your computer and use it in GitHub Desktop.
Database Getting Started
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Create a Database | |
| CREATE DATABASE IF NOT EXISTS mydatabase; | |
| -- Switch to using that database | |
| -- (so that all tables are created in this and not the master db) | |
| USE mydatabase; | |
| -- Create a Table | |
| CREATE TABLE IF NOT EXISTS mytable | |
| ( | |
| id int PRIMARY KEY AUTO_INCREMENT, | |
| email varchar(50) NOT NULL UNIQUE, | |
| firstname varchar(50), | |
| lastname varchar(50) | |
| ); | |
| -- See stuff in the table you created | |
| -- (You'll see nothing since this is empty at this point) | |
| SELECT * FROM mytable; | |
| -- Add some data to the table | |
| INSERT INTO mytable (email, firstname, lastname) | |
| VALUES | |
| ('jane@doe.com', 'Jane', 'Doe'), | |
| ('john@doe.com', 'John', 'Doe'), | |
| ('jenny@doe.com', 'Jenny', 'Doe'), | |
| ('penny@doe.com', 'Penny', 'Doe') | |
| ; | |
| -- See the data in the table | |
| SELECT * FROM mytable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment