Database Administration Flashcards

1
Q

How do you delete a database or table?

A

drop database database_name ;
drop table table_name ;

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

What is the syntax for the creation of a table in SQL?

A

create table table_name(
column_name datatype constraints,
column_name datatype constraints,
column_name datatype constraints
);

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

How do declare a foreign key in SQL?

A

create the table like normal with all the attributes but before closing add the following syntax:
fk_foreign_table_name
foreign key (foreign_key_name) references foreign_key_og_table_name (key_to_reference_name)
then close the whole query

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

How do you select all the data from a single column but avoid duplication?

A

select distinct column_name form table_name ;

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

How do you insert data into a table in SQL?

A

insert into table_name (column_1, column_2, column_3,……) values
(val_1, val_2, val_3,……),
(val_1, val_2, val_3,……),
(val_1, val_2, val_3,……),
(val_1, val_2, val_3,……),
;

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

How do you write dates in SQL?

A

“year-month-day”

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

How are boolean operations written in SQL?

A

or, and

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

How do you select data within a certain date range in SQL?

A

date >= “date”
then use the “and” operator to specify limits
-> to specify only the year:
year(date_column_name) >= year_as_int

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

How do you create a join in SQL?

A

select table_name.column, tablen_ame.column
from og_table
join foreign_table on og_table.foreing_key = foreign_table.primary_key

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

How do you set default values when creating a table in SQL?

A

create table table_name(
column_name data_type default default_value
) ;

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

How are floats declared in SQL?

A

decimal(number_of_total_digits, number_of_decimal_points)

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

How do you join two columns as one in a query?

A

concat(column1, “”, column2) as temp_col_name

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

How do you return only a certain percentage of column in SQL?

A

(math_operation on column_name) as temp_name

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

How do you sort query results in ascending or descending order?

A

select * from table_name order by column_name (asc/desc)

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

How many normal forms exist and how would you describe the first 3?

A

First, second, Third, and Boyce code normal form.

First normal form: This normal form aims to reduce redundancy by ensuring that all column data is atomic or a single value

Second normal form: This normal form aims at reducing redundancy by ensuring that every non-key on a table is fully dependent on the primary key

Third normal form: This normal form aims at reducing redundancy by eliminating transitive dependencies, meaning no non-key attribute can depend on another non-key attribute

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

what is normalisation?

A

Normalization is breaking down a database into small, manageable parts with the aim of reducing database redundancy.

16
Q

What is a database anomaly?

A

It is an undesired database behavior, usually caused by poor database organization.

17
Q

Explain deletion, update, and insertion anomalies.

A

Deletion anomaly:
It is a database anomaly that occurs when the deletion of a record, causes the intentional deletion of some other piece of data.

Update anomaly:
It is an anomaly that occurs when updating database data leads to inconsistencies or unintended changes across multiple records.

Insertion anomaly:
This is an anomaly that occurs when the insertion of new data into the database also requires the insertion of some piece of unrelated data.

18
Q

How do you sum all the values in a column?

A

SUM(column_name)

19
Q

How do you count all the records in a table using SQL?

A

count(*)

20
Q

How do you get the average value in a column?

A

where column_name > (select avg(column_name) from table_name) ;

21
Q

How do you update a record in SQL?

A

update table_name
set column_1 = val, colun_2 = val
where condition ;

22
Q

How do you query the names of all records whose attributes start or end with a given letter in SQL?

A

start:
where att_name like “letter%” ;
end:
where att_name like “%letter” ;
start and end:
where att_name like “%letter% ;

23
Q

Name one reserved word in SQL.

A

order

24
Q
A