SQL Statements Flashcards
(38 cards)
What is the INSERT Statement?
May insert a single, or many rows
How would you insert a single row?
Column names are optional, if column names are not specified, all columns must have values.

How would you insert multiple rows?

What is the DELETE Statement?
May delete a single or many (all) rows. The WHERE clause is optional. If not specified all rows will be deleted without warning.
How would you delete a single row?

How would you delete multiple rows?

How would you delete all rows?

What is the UPDATE Statement?
May update a single or many(all) rows. Where clause is optional. If not specified all rows will be updated without warning.
How would you update a single row?
The WHERE clause uses primary key to locate one record

How would you update multiple rows?
WHERE clause located many records

What is the GO Statement?
When a “batch” of statements have been executed, the end of the batch can be signified by a GO statement. The GO statement is usually optional, but can be required in certain circumstances. Some CREATE statements require that they are the first statement in a batch.
How would you set the date format in an SQL script?
SET DATEFORMAT ymd
Sets the date format to YYYY-MM-
What is a JOIN?
Frequently it is useful to join the data from multiple tables together.
SELECT column(s)
FROM firsttable
JOIN secondtable
ON firsttable.column = secondtable.colum
What are the different join types?
Inner join (default), left outer join, right outer join, full outer join, cross join.
How would you do an inner join?

How would you do a left outer join?

How would you do a right outer join?

How would you do a full outer join?

How would you do a cross join?

How would you join 3 tables?

How would you join a table with itself?

What is the proper date format to use?
Consider the following date: 01/02/03
Americans would say January 2, 2003
British would say February 1, 2003
Chinese would say February 3, 2001
Canadians wouldn’t be sure
What is the DATEDIFF function?
SELECT DATEDIFF(DAY, ‘2017-01-01’, ‘2018-09-01’)
Result is 608 days
SELECT DATEDIFF(MONTH, ‘2017-01-01’, ‘2018-09-01’)
Result is 20 months
SELECT DATEDIFF(YEAR, ‘2017-01-01’, ‘2018-09-01’)
Result is 1 year
How would you properly someones age with the datediff function?
SELECT FLOOR(DATEDIFF(DAY, ‘1999-11-15’, ‘2018-10-02’) / 365.25)






