mode 3 sql functionality Flashcards

1
Q

What is a natural key?

A

it is a key that was obtained from outside of the

  • database and is already unique
  • > example: pokemon, SSN, license plate, username…
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a Surrogate Key?

A

It is a key that was generated inside of the database itself.

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

What is a serial?

A

SERIAL is an integer

SERIAL keyword creates a new id in the table

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

What is a Composite Key?

A

two or more fields/ columns that create a unique value.

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

What is DQL?

A

Data Query Language

* SELECT statements is a part of DQL.

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

What is an alias?

A

its an alternate name,

alias allows you to give fields and tables another name the record set.

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

what is a record set?

A

It is the temporary table that you get back from a query

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

Different ways to use selects

A

SELECT * FROM employee;
–WHERE clause is a filter
SELECT * FROM employee WHERE title=’Sales Support Agent’;
– AND keyword only queries records if both conditions are met
SELECT * FROM employee WHERE title = ‘Sales Support Agent’ AND first_name = ‘Steve’;
– OR keyword queies records where only one of the conditions are met
SELECT * FROM employee WHERE first_name = ‘Andrew’ OR first_name = ‘Steve’;
–ALSO you can use >, =
SELECT * FROM employee WHERE reports_to >= (0+1);

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

How we use not equals on select

A
--is there not equals? 
/*
 * Ways to do not equals
 *  - !=
 *  - <>
 *  - NOT
 * */
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to do more generalized filters with strings?

A
    • LIKE keyword, finds patterns and ATTRIBUTES
  • —– ‘%’ is a wildcard that allows 0 or more characters
  • —– ‘_’ is a wildcard that allows one specific character
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we sort the data?

——

A

the keyword ORDER BY

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

Aggregate Functions

What is an aggregate function?

A

A calculation operating on a group of recrods/entriess, often producing 1 result;

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

Different types of aggregate functions

A

There are many different types of aggregate functions

  • Examples:
    • AVG: returns average on records
    • MIN: minimum value
    • MAX: max value
    • SUM: sum of elements in the column
    • DISTINCT:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the order of the WHERE, GROUP BY & HAVING keywords

A

order of the keywords matter, “WHERE” goes before “GROUP BY”

  • goes before “HAVING”
  • */
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an aggregate function?

A

calculation on a set records to get generally a single value

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

What is a scalar function?

A

function that works on individual records

17
Q

Types of Scalar functions

A

Numeric:
ABS(-99); FLOOR(88.77); CEIL(88.77);TRUNC(23432.23532,4);TRUNC(23432.23532,2);TRUNC(23432.23532, -2);

CHARACTERS
SELECT ‘HeLlo WOrlD’; UPPER(‘HeLlo WOrlD’);LOWER(‘HeLlo WOrlD’); LENGTH(‘HeLlo WOrlD’);

–DATE
SELECT CURRENT_DATE;
SELECT CURRENT_TIMESTAMP;