SQL Database Flashcards

1
Q

What is Database ?

A

Organized collection of data
Storage space for content/information (data)

Advantages:
• Control of data accuracy
• Data consistency
• Data manipulation (sort, retrieve, update…)
• Data Security

Disadvantages:
• Complexity, size, cost, maintenance

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

What is a Relational database? Advantages?

A

Relational databases use TABLES to store information.
It allows you to easily find specific information, sort based on any field, and generate reports that contain only certain fields from each record.

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

What is Schema?

A

Logical container for database objects (tables, views, triggers) that user creates

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

What is a Table? Can we have an empty Table?

A

Table is set of data elements (values) that is organized using columns (fields) and rows (records)
We can have an empty table

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

What is Field? What ‘part’ of the table?

A

Field is a database storage simplest unit (table column)

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

What is Record? What ‘part’ of the table?

A

Record is a row and it represents a single structured data set in table

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

What is Query?

A

Query is your request to the database to retrieve information

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

What is Report? How much information can you get in one report?

A

Report is the returned information to the specified query

Reports can be tailored to the needs of the data-user, making the information they extract much more useful

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

What is DBMS? Name a few popular databases

A

Database Management System is a software that controls the organization, storage, retrieval, security and integrity of data in dB

Popular Databases: ORACLE, Sybase, MySQL , DB2.

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

What is a PRIMARY KEY (PK) / FOREIGN KEY (FK)?

A

PRIMARY KEY (PK) is a unique identifier of every record in a table;

FOREIGN KEY (FK) is a column (or combination of columns) that is used to establish a relationship between the tables;
Foreign key is usually not unique (one-to-many relation) and shall always point to a primary key

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

What is a database NORMALIZATION?

A

NORMALIZATION is the dB process of dividing large tables into smaller tables and defining relationships between them;

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

What is SQL stands for? What does it do?

A

SQL stands for Structured Query Language. It is a database computer language, designed to retrieve and manage data, create and modify dB schema

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

Name a few Schema commands; Describe

A

CREATE - creates a table (index, view) in a database.
CREATE TABLE table1 (ID int, Last_Name varchar(255))

ALTER - used to add, delete, or modify columns in an existing table.
ALTER TABLE table1 ADD column1 varchar(255)
ALTER TABLE table1 DROP COLUMN column1
ALTER TABLE table1 MODIFY column1 varchar (255)

DROP - deletes a table (index, view).
DROP TABLE table1

TRUNCATE - deletes data in the table, but not table itself
TRUNCATE TABLE table1

COMMENT

RENAME

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

How to add a record to the table?

A

INSERT INTO table1 VALUES

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

How to change one field in the table?

A

ALTER TABLE table1 (MODIFY or RENAME COLUMN)
UPDATE table1 SET value1 WHERE field1=‘value2’

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

What is the difference between DROP, DELETE and TRUNCATE?

A

TRUNCATE removes ALL records from the table, same as DELETE FROM without WHERE clause
DROP deletes whole table

17
Q

What is Constraint ? Give couple constraints examples?

A

Constraint is used to define data integrity, restrict the values in a database
NOT NULL, PK, FK

18
Q

How to read data from dB?

A

SELECT * FROM table1

19
Q

What are the minimum requirements for the SELECT statement?

A

Two: SELECT, FROM

20
Q

Is WHERE required in the SELECT statement? Why?

A

Only SELECT and FROM clause are required. WHERE clause is used to specify the certain condition, not select the whole table

21
Q

How can I retrieve information for the whole table?

A

SELECT * FROM table1

22
Q

How would you read all first names from CUSTOMER table?

A

SELECT first_name FROM customer

23
Q

Is it possible to have duplicate first names in CUSTOMER table? How would you read only unique names?

A

SELECT DISTINCT first_name FROM customer

24
Q

How would you retrieve all employees 55+ years old, living in cities, starting with ‘San’, showing the oldest employee first?

A

SELECT * FROM employees
WHERE age>55 AND city LIKE ‘San%’
ORDER BY age DISC

25
Q

How would you read all employees who was born in Sep, Oct, and Nov?

A

SELECT * FROM employees WHERE to_char (birth_date, ‘mon’) IN (‘sep’, ‘oct’, ‘nov’)

26
Q

How would you choose all employees who do NOT have the address, stored in the system?

A

SELECT * FROM employees WHERE address IS NULL

27
Q

GROUP BY, HAVING, ORDER BY are required. True or False? Why?

A

They are optional, but must be in specific order

28
Q

How can i group result by specified criteria

A

GROUP BY used with aggregate functions COUNT(), MAX(), MIN(), SUM(), AVG()

29
Q

When are we using HAVING option?

A

After GROUP BY, we cant use WHERE, we use HAVING

30
Q

What is an aggregate function? Examples?

A

It return a single value, calculated from values in a column
COUNT()
MAX()
MIN()
SUM()
AVG()

31
Q

How can I count all records within a table?

A

SELECT COUNT(*) FROM table1

32
Q

How can I count all the records within the department?

A

SELECT COUNT(*) FROM table1 WHERE department_id=80

33
Q

How can I find the average salary?

A

SELECT AVG(salary) FROM table1