50 Interview Questions Flashcards
What is a database?
An organized collection of data
What is DBMS?
Database Management System. The software used to create and manage the database.
What is RDBMS?
Relational Database Management System. RDMS stores data in tables and the relationships between those tables can be defined by common fields.
What is SQL?
Structured Query Language. The standard language for RDBMS
What is the difference between SQL and mySQL?
SQL is the language used to manipulate relational databases. MySQL is a RDBMS
What are Tables and Fields?
Tables are collections of data stored in rows and columns. Fields are the columns. Rows are the records.
What are constraints in SQL?
Rules for data in a table. Can be applied during creation of a table or after creation using ALTER TABLE command
Constraint 1: NOT NULL
Prevents NULL values from being inserted into a column
Constraint 2: CHECK
Verifies that all values in a field satisfy a condition
Constraint 3: DEFAULT
Automatically assigns a default value if no value has been specified for the field.
Constraint 4: UNIQUE
Ensures unique values to be inserted into the field. Unlike primary key, there can be multiple unique constraints defined per table.
Constraint 5: INDEX
Indexes a field providing faster retrieval of records.
Constraint 6: PRIMARY KEY
Indexes a field providing faster retrieval of records. Must contain UNIQUE values and has implicit NOT NULL constraint. A table in SQL is strictly restricted to have one and only one primary key, which is comprised of single or multiple fields
Constraint 7: FOREIGN KEY
Comprises of single or collection of fields in a table that essentially refer to the PRIMARY KEY in another table. Foreign key constraint ensures referential integrity in the relation between two tables.
What is a JOIN?
The SQL Join clause is used to combine records (rows) from two or more tables in a SQL database based on a related column between the two.
INNER JOIN
Retrieves records that have matching values in both tables involved in the join.
SELECT *
FROM Table_A
INNER JOIN Table_B;
LEFT JOIN
Retrieves all the records/rows from the left and the matched records/rows from the right table. SELECT * FROM Table_A A LEFT JOIN Table_B B ON A.col = B.col;
RIGHT JOIN
Retrieves all the records/rows from the right and the matched records/rows from the left table. SELECT * FROM Table_A A RIGHT JOIN Table_B B ON A.col = B.col;
FULL (OUTER) JOIN
Retrieves all the records where there is a match in either the left or right table. SELECT * FROM Table_A A FULL JOIN Table_B B ON A.col = B.col;
What is a SELF-JOIN?
regular join where a table is joined to itself based on some relation between its own column(s).
SELECT A.emp_id AS “Emp_ID”,A.emp_name AS “Employee”,
B.emp_id AS “Sup_ID”,B.emp_name AS “Supervisor”
FROM employee A, employee B
WHERE A.emp_sup = B.emp_id;
What is a CROSS-JOIN?
a cartesian product of the two tables included in the join.
SELECT stu.name, sub.subject
FROM students AS stu
CROSS JOIN subjects AS sub;
What is an INDEX?
data structure that provides quick lookup of data in a column or columns of a table.An index helps to speed up SELECT queries and WHERE clauses, but it slows down data input, with the UPDATE and the INSERT statements. Indexes can be created or dropped with no effect on the data.
CREATE INDEX index_name /* Create Index */ ON table_name (column_1, column_2);
DROP INDEX index_name; /* Drop Index */
What is data integrity?
the assurance of accuracy and consistency of data over its entire life-cycle
What is a query?
is a request for data or information from a database table or combination of tables. A database query can be either a select query or an action query.