SQL Flashcards
What is SQL and how is it different from languages like JavaScript?
a domain-specific language used in programming and designed for managing data held in a relational database management system for handling structured data
it’s a declarative language, declaring what you want to happen but not how
How do you retrieve specific columns from a database table?
select “productId”,
“name”,
“price”
from “products
How do you filter rows based on some specific criteria?
select “productId”,
“name”,
“price”
from “products”
where “category” = ‘cleaning’;
What are the benefits of formatting your SQL?
readability
What are four comparison operators that can be used in a where clause?
=, <, >, and !=
How do you limit the number of rows returned in a result set?
Limit 5;
How do you retrieve all columns from a database table?
Select *
From “whatever”;
How do you control the sort order of a result set?
Order by “price” will give lowest first or asc
Order by “price” desc gives highest first
How do you add a row to a SQL table?
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’)
returning *;
What is a tuple?
a list of values
How do you add multiple rows to a SQL table at once?
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
returning *;
How do you get back the row being inserted into a table without a separate select statement?
Returning *; after
How do you update rows in a database table?
update “actors”
set “firstName” = ‘Baby’,
“lastName” = ‘Yoda’
where “actorId” = ‘test’;
Why is it important to include a where clause in your update statements?
So that you only update one row in the table
How do you delete rows from a database table?
delete
from “products”
where “productId” = 24
returning *;