Unit 3 Flashcards
(28 cards)
SELECT * INTO Table
used for copy data to another.
DELETE
remove row(s).
TRUNCATE
remove all rows.
DROP
remove table.
UPDATE
change the values in row(s) for one table at a time. Used with SET and WHERE.
SET
specific columns to contain specific values. Nested select statement can be used here to make that value and aggregate. Used with UPDATE.
Which of these commands does not change the tables in a DB?
- INSERT
- DELETE
- UPDATE
- SELECT
SELECT
LIKE
Used with the “%” character. Also used as NOT LIKE.
SELECT CONCAT(attr1, attr2) FROM Table
Used to represent values of two attributes in one column.
SELECT studentName AS Name FROM TABLE
Alias, used to label columns of results to clarify query results.
UPPER(), LOWER()
change casing of results.
LTRIM(), RTRIM()
take trailing spaces or specific characters off of values in column.
LEFT(), RIGHT()
selecting only a part of the characters in values in column.
CAST(attr1 AS INT)
Used to cast the datatypes of a column. Usually used with ROUND().
WHERE empID IN (‘AJ01’, ‘GB01’)
Used to find a list of specific values in a column.
Is CAST() the same as ROUND()
CAST() changes the datatype and chops off extra numbers instead of rounding, ROUND() rounds the value.
ROUND(151.42) AS INT
Rounds the values to a less precise datatype.
DATEDIFF(metric, attr1, attr2)
- Used to find difference between to dates according to a time metric.
- Ex: DATEDIFF(years, birthDate, GETDATE()) finds a person’s age in years.
- date2 - date1
DATEADD(metric, metric added, attr1)
- Not used to edit values in DB; used to add values pulled from DB to format query.
- Ex: DATEADD(years, 1, hireDate) returns the 1 year anniversary for employee’s hire.
- Ex: DATEADD(months, -6, hireDate) returns the date 6 months before an employee was hired. DATEADD can be used to “DATESUBTRACT.”
SELECT TOP 2 WITH TIES empID, firstName, lastName, salary
Returns even more than the top 2 values if the second highest ties with lower ranked values.
What order is alphabetical ascending?
A to Z
What order is numerical ascending?
0 to 100; increasing.
OFFSET 3 rows
offsets query results. OFFSET 3 Rows: query results are everything omitting the top 3 rows that should have appeared without OFFSET; Used with FETCH NEXT
FETCH NEXT 5 rows only;
Used with OFFSET; works with OFFSET; Finds n rows after OFFSET. In the above query it works with OFFSET to return rows 4, 5, 6, 7, 8.