SQL Exercises Flashcards

1
Q

Database, Database Management System and Database System

A
DB = collection of related data
DBMS = provides a set of services to create, access, maintain databases
DBS = DBMS + DB
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Information and Data

A

Data are of recorded facts and numbers only

Infomation is data presented in a meaningful context and processed by aggregating, comparing or similar operations

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

Referential Integrity

A

Referential integrity means that each value of the foreign key has to exist as a value of the primary key in the referenced table.

A DBMS ensures that

  • no new can be entered without an existing customer number
  • no costumer data can be deleted as long as there are orders
  • no customer IDs can be changed without changing the dependent order tuples
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Keys

A

Super Key:
- identifies each tuple (row) of the relation uniquely. It can consist of one or more attributes

Candidate Key:
- a super key with minimal attributes

Primary Key:
- the chosen Candidate Key to identify a tuple in the relation

Foreign Key:
- attribute in a relation that matches the primary key of another table. It can be used to cross-reference relations

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

Create a table

A

CREATE TABLE tableName
(
column1 datatype [default value/ constraint],
column 2 datatype [default value/ constraint],
… … …
);

Do not forget the paranthesis and semicolon

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

Data Type

A

Integer/ int:
- Integer approc +- 2.147.483.000

Decimal (x,y)/ Dec (x,y):
- Formatted number mit x decimal digits that can be stored in total (precision) and y decimal digits right of the decimal point (scale)

Date:
- Date
Time:
- Time
Datetime:
- Date and Time

Character (n)/ char (n):
- Text with a length of exactly n characters, fixed length

Varchar (n):
Text with a mx. length of n characters, variable length

Use quotation marks for Char and Varchar

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

Insert data into a table

A
INSERT INTO tableName
VALUES
(
values in the right order!
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Select data from a table

A

SELECT columnName
FROM tableName
WHERE columnName = condition
;

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

Join data from tables

A

SELECT t1N.columnName, t2N.columnName, t3N.columnName

FROM table1Name t1N
JOIN table2Name t2N
ON t1N.columnName = t2N.columnName (condition)

JOIN table3Name t3N
ON t2N.columnName = t3N.columnName (any condition)

WHERE columnName = condition
;

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

Giving out the Sum of some amounts

A

SELECT SUM(amount1)
FROM
WHERE

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

Giving out the number of entry that fulfill a certain condition

A

SELECT COUNT(*)
FROM
WHERE

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

Selecting an entry where an entry fulfills a condition and another condition which is linked to a function

A
SELECT 
FROM
WHERE condition 1
AND condition 2 = SELECT MAX()
FROM
WHERE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Ordering entrys

A

After the query you put

ORDER BY entry ASC or DESC

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

Searching texts in entry for certain characters or words

A

WHERE column LIKE ‘….’
% means anything can come before and after
_ one character, in front or behind it

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

Selecting values which are not in a table

A

WHERE column IS NOT (SELECT column FROM table)

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

Daten ordnen nachdem man die Anzahl von Zellen gezählt hat oder die Summe vom Inhalt

A

GROUP BY

Example
SELECT column1; COUNT(column2); SUM(column3)
FROM
GROUP BY column1

Gibt an wie viele Einträge von column2 verhanden sind in der Reihe von column1 und die Summe der Einträge von in column3.

17
Q

Spalten in der ausgegeben Tabelle mitbestimmten Namen versehen

A

SELECT coumn1 AS name
FROM

Example
SELECT name AS friend