SQL STATEMENTS
SQL is a programming language designed to manipulate and manage data stored in relational databases.
- A relational database is a database that organizes information into one or more tables.
- A table is a collection of data organized into rows and columns.]
A statement is a string of characters that the database recognizes as a valid command.
CREATE TABLE creates a new table.
INSERT INTO adds a new row to a table.
SELECT queries data from a table.
UPDATE edits a row in a table.
ALTER TABLE changes an existing table.
DELETE FROM deletes rows from a table.
SQL statements that create, edit, and delete data.
// =============================================== //
WRITE QUERIES
// =============================================== //
## CREATE new table, name celebs ##
CREATE TABLE celebs
---
## Add a row - insert new record ##
INSERT INTO celebs (id, name, age) VALUES (1, 'Justin Bieber', 21);
---
## To view the row you just created, under the INSERT statement type
* view all ##
SELECT * FROM celebs;
---
## SELECT name from celebs ##
SELECT name FROM celebs;
---
## UPDATE edit a row in the table ##
UPDATE celebs
SET age = 22
WHERE id = 1;
---
## WHERE is a clause that indicates which row(s) to update with the new column value.
## ALTER TABLE Add a new column to table twitter_handle ##
ALTER TABLE celebs ADD COLUMN twitter_handle TEXT;
SELECT * FROM celebs;
---
## Update the table to include Taylor Swift's twitter ##
UPDATE celebs
SET twitter_handle = '@taylorswift13'
WHERE id = 4;
SELECT * FROM celebs;
---
## Delete all of the rows that have a NULL value in the twitter column. Above SELECT type ##
DELETE FROM celebs WHERE twitter_handle IS NULL;
------------------------------------------