SQL Flashcards
What is SQL and how is it different from languages like JavaScript?
it is a querying language that stores info and u can organize the info. It is declarative, tell it what you want
How do you retrieve specific columns from a database table?
select then add the column headers
use from keyword table
select “”
from “”
How do you filter rows based on some specific criteria?
where “” = ‘’
where keyword then the column header in double quotes comparison operators then specific criteria in single quotes
What are the benefits of formatting your SQL?
organization and time efficiency
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?
limit keyword followed by a numerical value
How do you retrieve all columns from a database table?
select * (univeral key)
How do you control the sort order of a result set?
order by keyword then followed by a column header in double quotes then descending if descending
How do you add a row to a SQL table?
The statement begins with the insert keyword.
The table to insert into is specified in “ double quotes.
The list of columns being inserted is wrapped in () parenthesis.
The values being inserted are also wrapped in () in parenthesis in the same order as the columns they belong to.T ext values are wrapped in ‘ single quotes.
EX:
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);
What is a tuple?
The values being inserted are also wrapped in () in parenthesis in the same order as the columns they belong to. In SQL, a list of values is referred to as a tuple.
How do you add multiple rows to a SQL table at once?
values
(‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
put a comma inbetween then add the second values in the same order as above
How do you get back the row being inserted into a table without a separate select statement?
Returning keyword followed by asterisk at the end of the query and then a semicolon;
How do you update rows in a database table? Why is it important to include a where clause in your update statements?
update “products”
set “price” = 200,
“name” = ‘Super ShakeWeight’,
“description” = ‘Makes you ULTRA strong!’
where “productId” = 24;
update keyword then set keyword then where keyword; It is so u do not update everything within a column to one value
How do you delete rows from a database table?
delete from “products”
where “productId” = 24
returning *
delete from “products”
where “category” = ‘cleaning’
and “price” < 20
Properly start with delete from (a table name) where is the column title and value at a certain point.
Second option is if you have multiple criteria
How do you accidentally delete all rows from a table?
delete from “products”; IF YOU DO NOT SPECIFY WHERE THEN IT WILL DELETE EVERYTHING ON A TABLE