Created
January 16, 2017 05:31
-
-
Save welding3000/d56abdc951710fa8098a67f874a389f4 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* SELECT == queries data from a table. | |
*/ | |
// * CREATE TABLE === creates a new table. | |
CREATE TABLE celebs (id INTEGER, name TEXT, age INTEGER); | |
/* ------------------------------------------------------------------------- */ | |
/** // * INSERT INTO == adds a new row to a table | |
* This INSERT statement inserts new rows into a table. | |
* You can use the INSERT statement when you want to add new records. | |
*/ | |
INSERT INTO celebs (id, name, age) VALUES (1, 'Justin Bieber', 21); | |
INSERT INTO celebs (id, name, age) VALUES (2, 'Beyonce Knowles', 33); | |
INSERT INTO celebs (id, name, age) VALUES (3, 'Jeremy Lin', 26); | |
INSERT INTO celebs (id, name, age) VALUES (4, 'Taylor Swift', 26); | |
/** | |
# INSERT INTO === is a clause that adds the specified row or rows. | |
# celebs === is the name of the table the row is added to. | |
# (id, name, age) === is a parameter identifying the columns that data will be inserted into. | |
# VALUES === is a clause that indicates the data being inserted | |
*/ | |
/* ------------------------------------------------------------------------- */ | |
/** // * ALTER TABLE == changes an existing table. | |
* The ALTER TABLE statement added a new column to the table | |
* You can use this command when you want to add columns to a table | |
*/ | |
ALTER TABLE celebs ADD COLUMN twitter_handle TEXT; | |
/** | |
# ALTER TABLE === is a clause that lets you make the specified changes. | |
# celebs === is the name of the table that is being changed. | |
# ADD COLUMN === is a clause that lets you add a new column to a table. | |
# twitter_handle === is the name of the new column being added | |
# TEXT === is the data type for the new column | |
*/ | |
/* ------------------------------------------------------------------------- */ | |
/** // * UPDATE == edits a row in a table. | |
* The UPDATE statement edits a row in the table. | |
* You can use the UPDATE statement when you want to change existing records. | |
*/ | |
UPDATE celebs | |
SET age = 22 | |
WHERE id = 1; | |
UPDATE celebs | |
SET twitter_handle = '@taylorswift13' | |
WHERE id = 4; | |
/** | |
# UPDATE === is a clause that edits a row in the table. | |
# celebs is the name of the table. | |
# SET === is a clause that indicates the column to edit. | |
# age is the name of the column that is going to be updated | |
# 22 is the new value that is going to be inserted into the age column. | |
# WHERE === is a clause that indicates which row(s) to update with the new column value. | |
# Here === the row with a 1 in the id column is the row that will have the age updated to 22. | |
*/ | |
/* ------------------------------------------------------------------------- */ | |
/** // * DELETE FROM == deletes rows from a table. | |
* The DELETE FROM statement deletes one or more rows from a table. | |
* You can use the statement when you want to delete existing records. | |
*/ | |
DELETE FROM celebs WHERE twitter_handle IS NULL; | |
/** | |
# DELETE FROM === is a clause that lets you delete rows from a table. | |
# celebs === is the name of the table we want to delete rows from. | |
# WHERE === is a clause that lets you select which rows you want to delete. | |
# Here we want to delete all of the rows where the twitter_handle column IS NULL | |
# IS === NULL is a condition in SQL that returns true when the value is NULL and false otherwise | |
*/ | |
/* ------------------------------------------------------------------------- */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment