SQL 1 Flashcards

1
Q

datepart

A

component of date i.e
date, month, week, year, hour minute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

dateadd function

A

needs to have
1. datepart
2. number
3, date or datetime in this order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

If a function does not take an argument

A

It does not need to be in ()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Concatenation Operator

A

”+” in SQL server only
// (actually straight lines not slashes, jsut cant find keyboard character for straight parallel lines) - Oracle only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Cast function

A

changes data from one data type to another

Ex. For concat funcitons, data types need to be the same. Would use cast to make both the same to then add together.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Convert function

A

similar to cast function, specific to SQL server in changing data types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Datediff function

A

calculates the difference between two dates (Date diff)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

datefromparts

A

returns the date (integer)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Concat function

A

” select concat (prov_name, ‘,’, Clinician_title) “Provider’

Combines text of two different fields to one. Better than just using + operator bc if there is a null value, + won’t return anything. Need to use concat function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Coalesce function

A

returns the first non null input

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Len function

A

returns the # of characters in any string
Can also use Length()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

determining the cardinality of the relationship

A

When using a JOIN, you need to identify how each relationship is defined in order to guide you to using the relationship in a query

Ex one to many, many to one exactly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Inner Join

A

only includes rows that represent a match between two tables

Good for relationships that don’t include cardinality of “zero, or” on either side

Good to use if you need only valid matches (non-nulls)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Outer Join

A

Returns all rows in the left table + remaining matching rows in both tables (non null results in right table)

Good to use when there is a “zero or”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

cross join

A

Usually done on accident; rarely used

can happen if the word Join is omitted from the from clause or a “,” is accidentally input

Leads to being a cartesian product
- usually results in massive results, slows performance
- meaningless results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Count function

A

returns the # of rows of the query

in the select clause

“select count (*) from …

17
Q

From Clause

A

Evaluated first

18
Q

Foreign keys

A

relationships are represented by foreign keys. Typically:

Foreign_key_column = primary_key_column

19
Q
A
20
Q

aggregate function

A

summarize a group of rows

21
Q

Sum aggregate function

A

allows you to add up the values of a column across rows
- null values are ignored

22
Q

Max aggregate function

A

returns the max numeric value
- for a column that is the same value or null, it will return that value

23
Q
A