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
What must happen for third normal form (3NF) ?
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
Have a look at inner joins
Powerpoint
27
Name some sql functions
ascii,CHR,initcap, position,format, CONCAT,CURRENT_DATE,date_part,date_trunc
28
What does the ascii function do and write some example code.
It returns the ascii decimal value of a character. E.g select ascii( 'e') = 1010
29
What does the CHR function do?
It returns a character when given a ascii decimal value. E.g. select CHR(65) = A
30
What does the initcap function do and write some example code.
It changes the case of a given string E.g select initcap('hi i am your lecturer'); = Hi I Am Your Lectuerer
31
What does the position function do and write some example code.
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
What does the format function do and write some example code.
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
What does the CONCAT function do and write some example code
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
what do the date_part and date_trunc fucntions do?
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
What does the age function do?
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
What issue do JSON documents solve ?
JSON documents can store many datatypes meaning that the issue of many datatypes in a database can be solved
37
Name some Json doc store databases?
. Mongo DB . Couch DB . Document DB
38
Give some info on key value databases.
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
Give some info on graph databases
. 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
Give some info on wide column databases
.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
What does JSON stand for
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
State the main usage and differences of JSON
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
Is joins necessary when using JSON
No, because we don't have entities.
44
Describe the steps to create a table that makes use of JSON
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
How do you insert into JSON rows
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
What are the 2 operators to get data from json rows
->> data by key -> by text
47
What is the difference between ->> and ->
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
Name the basic wildcards and what they do
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
What are the 5 main aggregate functions and what do they do.
count, sum, avg, min, max