Databases Flashcards
How do you add a row to a SQL table?
insert into “table-name” (“columns”…)
values ( ‘value’)
What is a tuple?
A single row of a table, which contains a single record for that relation.
How do you add multiple rows to a SQL table at once?
INSERT INTO table_name (column1, column2)
VALUES (value1, value2);
How do you get back the row being inserted into a table without a separate select statement?
adding returning *; at the end
How do you update rows in a database table?
UPDATE table_name
SET some_column = some_value
WHERE some_column = some_value;
Why its important to include a where clause in your update statements?
you might update every row
How do you delete rows from a database table?
DELETE FROM students
WHERE enrolled_status = ‘not_current’;
Optional
ALTER TABLE students
DROP COLUMN history;
How do you accidentally delete all rows from a table?
By typing delete from *
What is SQL and how is it different from languages like JavaScript?
SQL (Structured Query Language) is design to managing and manipulating data. It’s not a programing language.
How do you retrieve specific columns from a database table?
using SELECT “specific-column”
FROM “table-name”
How do you filter rows based on some specific criteria?
Using where clause.
SELECT column1, column2, …
FROM table_name
WHERE condition;
What are the benefits of formatting your SQL?
everything looks “clearer”, code is much easier to read
What are four comparison operators that can be used in a where clause?
,= ,!= , <=, >=
How do you limit the number of rows returned in a result set?
Using limit clause
How do you retrieve all columns from a database table?
Using asterisk *