Database Flashcards

1
Q

What is a database?

A

In simple terms, a database is a structured collection of data that is stored and organized in a computer system.

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

What does ERD stand for?

A

Entity relationship diagram

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

What is an ERD?

A

A visual representation that illustrates the relationships between entities (objects or concepts) in a database.

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

What is an entity?

A

An entity is a noun that defines one single thing

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

What notoation should you use for ERD’s?

A

Crows foot

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

What is another name for a record?

A

Tuple

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

What does DBMS stand for?

A

Database management system

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

What are the 2 main languages SQL is made up of

A
  • Data Definition Language (DDL)
    Data Manipulation Language (DML)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is SQL

A

Structured Query Language, is a programming language used for managing and manipulating relational databases.

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

Describe Data Definition Language (DDL) and give examples

A

DDL commands define the structure of the database
* Allows the DBA or users to describe and name entities, attributes and relationships required for the applications that access it and associated integrity and security constraints.
Examples are :
CREATE TABLE, ALTER TABLE, DROP DATABASE, DROP TABLE, RENAME TABLE

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

Describe Data Manipulation Language (DML)

A
  • DML is data manipulation language which is used for selecting, inserting, updating and deleting data in a database.
    Example :
    . SELECT
    . INSERT
    . UPDATE
    . DELETE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a query ?

A

A query is code that interacts with the data base

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

Give some advantages of DBMS

A
  • Data can be managed more easier
  • Users can be provided with improved access to data
  • Provides an integrated view of an enterprise’s operation
  • The risk of inconsistency is improved
    Security can be controlled
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a constraint?

A

constraints are used to specify rules for the data in a table

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

Give an example of some constraints

A

UNIQUE, NOT NULL

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

What are the 4 types of relationships in a ERD?

A

. zero to many
. many to many
. 1 to 1
. 1 to many

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

What relationship do we prefe use in a relational database?

A

1 to many but we can represent others

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

What is a primary key?

A

A unique key to identify a record?

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

What is a foreign key ?

A

This is a field/attribute that provides a link between 2 tables. They are always at the many end of the relationship

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

What is a composite key?

A

It is a key made up of a primary and foreign key.

21
Q

What is normalisation?

A

Normalisation is designing the best possible database with reduced data redundancy and best efficiency

22
Q

What is data that has not been normalized called?

A

0NF (unormalised)

23
Q

What must happen for first normal form (1NF)?

A

1.) It should only have single(atomic) valued attributes/columns.(1 value per field and no repeating data)
2.) Values stored in a column should be of the same domain(same data type)
3.) All the columns in a table should have unique names.
4.) The order in which data is stored, does not matter.

24
Q

What must happen for second normal form (2NF) ?

A
  1. ) Be in 1NF
    2.) Have no partial dependency
25
Q

What must happen for third normal form (3NF) ?

A

1.) It is in the Second Normal form.
2.) Doesn’t have transitive(non-key) dependency meaning all fields depend on the primary key and nothing but the primary key.

26
Q

Have a look at inner joins

A

Powerpoint

27
Q

Name some sql functions

A

ascii,CHR,initcap, position,format, CONCAT,CURRENT_DATE,date_part,date_trunc

28
Q

What does the ascii function do and write some example code.

A

It returns the ascii decimal value of a character.
E.g select ascii( ‘e’) = 1010

29
Q

What does the CHR function do?

A

It returns a character when given a ascii decimal value.
E.g. select CHR(65) = A

30
Q

What does the initcap function do and write some example code.

A

It changes the case of a given string
E.g select initcap(‘hi i am your lecturer’); = Hi I Am Your Lectuerer

31
Q

What does the position function do and write some example code.

A

It returns the location of a character in a string. NOTE it starts from 1 and not 0.

E.g.
select position (‘B’ in ‘A B C’) = 3

32
Q

What does the format function do and write some example code.

A

The format function format arguments based on an input format string.

E.g.
select format (‘Hello %s’ , cust_fname) from customer; = see slide notes for answer

33
Q

What does the CONCAT function do and write some example code

A

The CONCAT function concatenates strings in query outputs
This function can be used with a separator or without

E.g.
SELECT CONCAT(CIST_FNAME, ‘ ‘, CUST_LNAME) FROM CUSTOMER WHERE CUST_ID = 3; = David mamattah
Note the answer is in a column called concat

34
Q

what do the date_part and date_trunc fucntions do?

A

date_part gets a specific part of date
e.g. select date_part(‘year’, ‘dob’) from users where users id = 6;

date_trunc does a siilar thing

35
Q

What does the age function do?

A

It just returns how long its been between 2 given timestamps

e.g.
SELECT age(timestamp ‘2015-01-15’, timestamp ‘1972-12-28’);
= 42 years 18 days]

NOTE IF NOT GIVEN A 2ND TIMESTAMP IT TAKES THE 2ND TIMESTAMP AS THE CURRENT DATE

36
Q

What issue do JSON documents solve ?

A

JSON documents can store many datatypes meaning that the issue of many datatypes in a database can be solved

37
Q

Name some Json doc store databases?

A

. Mongo DB
. Couch DB
. Document DB

38
Q

Give some info on key value databases.

A

It work similar to relational database
* The format of a keyvalue database is a set of keys and values
* They are very fast and have only small records
* The language is not at all complicated
○ Put, Get, Delete
○ Only 2 attributes to get back, keys and values
* Example of key value data stores are as follows
○ Amazon
DynamoDB
○ Couchbase
○ Redis

39
Q

Give some info on graph databases

A

. They’re more visual and all based on graph theory
. They are used to store information about things and the links between them.
exampes include :
○ Neo4j
○ Tigergraph
GraphDB

40
Q

Give some info on wide column databases

A

.Similar to relational databases
. A row does not have to be the same length as the row above or below.
Examples include:
○ Google Bigtable
○ Apche Hbase
Scylla

41
Q

What does JSON stand for

A

Java Script object notation
* It is an open format standard. It consists of key/value pairs.
* The user decides what the keys are and what each value is
* This includes the data types of the values

42
Q

State the main usage and differences of JSON

A

The main usage of JSON is data transfer between servers and web application
* The main differences between JSON type data and traditional data are:
○ We do not know the structure of each record
○ We do not have a known schema (no need for ERDs)
○ We do not know what the data types will be

43
Q

Is joins necessary when using JSON

A

No, because we don’t have entities.

44
Q

Describe the steps to create a table that makes use of JSON

A

Create a table with your name for it and fields.
Make sure one of the fields is called data and its type is jSON
e.g. data json

45
Q

How do you insert into JSON rows

A

You would do a normal insert statement but where you put the values you add {} and then place your key values

E.g. INSERT INTO json_data (data) VALUES (‘{“fname” : “John”, “lname” : “Doe”, “order” :{“Item” : “IPA”, “QTY” : 6}}’);

46
Q

What are the 2 operators to get data from json rows

A

-» data by key
-> by text

47
Q

What is the difference between -» and ->

A

returning data by key(-») just gets rid of the quotation marks in the output

e.g. SELECT data -» ‘customer’ AS customer FROM json_data;

The output is
Lily Smith
Jade Davies
Josh Green-Gardner
(4 rows)

48
Q

Name the basic wildcards and what they do

A

Wildcard operators are used with the like operator.

One is %

e.g.
a% Finds any values that starts with “a”

%a Finds any values that ends with “a”

49
Q

What are the 5 main aggregate functions and what do they do.

A

count, sum, avg, min, max