sql-update-insert-delete Flashcards
How do you add a row to a SQL table?
INSERT INTO “table_name” (“col1”, “col2”)
VALUES (“col1val”, “col2val”)
What is a tuple?
A tuple is a batch of values surrounded by parenthesis
How do you add multiple rows to a SQL table at once?
Using multiple comma separated tuples after the VALUES keyword
How do you get back the row being inserted into a table without a separate select statement?
Use RETURNING * or RETURNING “col_names”
How do you update rows in a database table?
UPDATE “table_name”
SET “col1” = 100,
“col2” = 40
WHERE “col” = 10;
Why is it important to include a where clause in your update statements?
If you dont include a WHERE clause then the entire column will become that value.
How do you delete rows from a database table?
DELETE FROM “table_name”
WHERE “col1” = “col1val”
How do you accidentally delete all rows from a table?
DELETE FROM “table_name”