Database Administration Flashcards
How do you delete a database or table?
drop database database_name ;
drop table table_name ;
What is the syntax for the creation of a table in SQL?
create table table_name(
column_name datatype constraints,
column_name datatype constraints,
column_name datatype constraints
);
How do declare a foreign key in SQL?
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 do you select all the data from a single column but avoid duplication?
select distinct column_name form table_name ;
How do you insert data into a table in SQL?
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 do you write dates in SQL?
“year-month-day”
How are boolean operations written in SQL?
or, and
How do you select data within a certain date range in SQL?
date >= “date”
then use the “and” operator to specify limits
-> to specify only the year:
year(date_column_name) >= year_as_int
How do you create a join in SQL?
select table_name.column, tablen_ame.column
from og_table
join foreign_table on og_table.foreing_key = foreign_table.primary_key
How do you set default values when creating a table in SQL?
create table table_name(
column_name data_type default default_value
) ;
How are floats declared in SQL?
decimal(number_of_total_digits, number_of_decimal_points)
How do you join two columns as one in a query?
concat(column1, “”, column2) as temp_col_name
How do you return only a certain percentage of column in SQL?
(math_operation on column_name) as temp_name
How do you sort query results in ascending or descending order?
select * from table_name order by column_name (asc/desc)
How many normal forms exist and how would you describe the first 3?
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