DBA adminstrator interview questions Flashcards _ Quizlet
DBA adminstrator interview questions Flashcards _ Quizlet
Save
an organized collection of data, stored and retrieved digitally from a remote or local
What is a database?
computer system.
RDBMS stands for Relational Database Management System. The key difference here,
compared to DBMS, is that RDBMS stores data in the form of a collection of tables
DBMS vs RDBMS and relations can be defined between the common fields of these tables. Most
modern database management systems like MySQL, Microsoft SQL Server, Oracle,
IBM DB2 and Amazon Redshift are based on RDBMS.
SQL stands for Structured Query Language. SQL lets you access and manipulate
What is SQL?
databases.
A table is an organized collection of data stored in the form of rows and columns.
What are Tables and Fields? Columns can be categorized as vertical and rows as horizontal. The columns in a
table are called fields while the rows can be referred to as records.
Constraints are used to specify the rules concerning data in the table. It can be
applied for single or multiple fields in an SQL table during creation of table or after
creationg using the ALTER TABLE command. The constraints are:
NOT NULL - Restricts NULL value from being inserted into a column.
CHECK - Verifies that all values in a field satisfy a condition.
What are Constraints in SQL? DEFAULT - Automatically assigns a default value if no value has been specified for the
field.
UNIQUE - Ensures unique values to be inserted into the field.
INDEX - Indexes a field providing faster retrieval of records.
PRIMARY KEY - Uniquely identifies each record in a table.
FOREIGN KEY - Ensures referential integrity for a record in another table.
A field (or group of fields) that uniquely identifies a given entity in a table
/ Create table with a single field as primary key /
A primary key of one table that appears as an attribute in another table and acts to
provide a logical relationship between the two tables
/ Create table with foreign key - Way 1 /
(INNER) JOIN: Retrieves records that have matching values in both tables involved in
the join. This is the widely used join for queries.
SELECT * FROM Table_A
JOIN Table_B;
Self-join is set to be query used to compare to itself. This is used to compare values in
a column with other values in the same column in the same table. ALIAS ES can be
used for the same table comparison.
A cross join does not have a WHERE or ON clause, therefore it produces the
Cartesian product of the tables involved in the join. The size of a Cartesian product
result set is the number of rows in the first table multiplied by the number of rows in the
second table.
What is a cross join?
/ Create Index /
/ Drop Index /
There are different types of indexes that can be created for different purposes:
Non-unique indexes, on the other hand, are not used to enforce constraints on the
tables with which they are associated. Instead, non-unique indexes are used solely to
improve query performance by maintaining a sorted order of data values that are
used frequently.
Clustered indexes are indexes whose order of the rows in the database correspond to
the order of the rows in the index. This is why only one clustered index can exist in a
given table, whereas, multiple non-clustered indexes can exist in the table.
The only difference between clustered and non-clustered indexes is that the
database manager attempts to keep the data in the database in the same order as the
corresponding keys appear in the clustered index.
Clustering index can improve the performance of most query operations because
they provide a linear-access path to data stored in the database.
As explained above, the differences can be broken down into three small factors -
Clustered index modifies the way records are stored in a database based on the
indexed column. Non-clustered index creates a separate entity within the table which
references the original table.
What is the difference between Clustered
and Non-clustered index?
Clustered index is used for easy and speedy retrieval of data from the database,
whereas, fetching records from the non-clustered index is relatively slower.
In SQL, a table can have a single clustered index whereas it can have multiple non-
clustered indexes.
What is Data Integrity? Data being ACCURATE and CONSISTENT throughout its life.
A command to retrieve data from tables
/ select query /
UPDATE myDB.students
SET fname = 'Captain', lname = 'America'
WHERE student_id = 1;
WHERE clause in SQL is used to filter records that are necessary, based on specific
conditions.
ORDER BY clause in SQL is used to sort the records based on some field(s) in
ascending (ASC) or descending order (DESC).
HAVING clause in SQL is used to filter records in combination with the GROUP BY
clause. It is different from WHERE, since WHERE clause cannot filter aggregated
records.
Certain conditions need to be met before executing either of the above statements in
SQL -
Each SELECT statement within the clause must have the same number of columns
The columns must also have similar data types
The columns in each SELECT statement should necessarily have the same order
DECLARE a cursor after any variable declaration. The cursor declaration must always
be associated with a SELECT Statement.
Open cursor to initialize the result set. The OPEN statement must be called before
fetching rows from the result set.
FETCH statement to retrieve and move to the next row in the result set.
Call the CLOSE statement to deactivate the cursor.
Finally use the DEALLOCATE statement to delete the cursor definition and release the
associated resources.
What is a cursor?
/ Declare Cursor Name/
OPEN db_cursor
FETCH next
FROM db_cursor
INTO @name
CLOSE db_cursor
DEALLOCATE db_cursor
Entity: An entity can be a real-world object, either tangible or intangible, that can be
easily identifiable. For example, in a college database, students, professors, workers,
departments, and projects can be referred to as entities. Each entity has some
associated properties that provide it an identity.
What are Entities/Relationships
Relationships: Relations or links between entities that have something to do with each
other. For example - The employees table in a company's database can be associated
with the salary table in the same database.
One-to-One - This can be defined as the relationship between two tables where each
record in one table is associated with the maximum of one record in the other table.
One-to-Many & Many-to-One - This is the most commonly used relationship where a
record in a table is associated with multiple records in the other table.
List the different types of relationships in
SQL.
Many-to-Many - This is used in cases when multiple instances on both sides are
needed for defining a relationship.
A view in SQL is a virtual table based on the result-set of an SQL statement. A view
What is a view? contains rows and columns, just like a real table. The fields in a view are fields from
one or more real tables in the database.
What is normalization?
Normalization represents the way of organizing structured data in the database
efficiently. It includes creation of tables, establishing relationships between them, and
defining rules for those relationships. Inconsistency and redundancy can be kept in
check based on these rules, hence, adding flexibility to the database.
the process of transforming a logical data model into a physical model is efficient for
the most-often-needed tasks
OR
TRUNCATE command is used to delete all the rows from the table and free the space
containing the table.
What are the TRUNCATE, DELETE and
DROP statements? TRUNCATE TABLE Candidates;
DROP command is used to remove an object from the database. If you drop a table,
all the rows in the table is deleted and the table structure is removed from the
database.
If a table is dropped, all things associated with the tables are dropped as well. This
includes - the relationships defined on the table with other tables, the integrity checks
What is the difference between DROP and and constraints, access privileges and other grants that the table has. To create and
TRUNCATE statements? use the table again in its original form, all these relations, checks, constraints,
privileges and relationships need to be redefined. However, if a table is truncated,
none of the above problems exist and the table retains its original structure.
The TRUNCATE command is used to delete all the rows from the table and free the
space containing the table.
What is the difference between DELETE and
The DELETE command deletes only the rows from the table based on the condition
TRUNCATE statements?
given in the where clause or deletes all the rows from the table if no condition is
specified. But it does not free the space containing the table.
A scalar function returns a single value based on the input value. Following are the
widely used SQL scalar functions:
LEN() - Calculates the total length of the given field (column).
UCASE() - Converts a collection of string values to uppercase characters.
LCASE() - Converts a collection of string values to lowercase characters.
MID() - Extracts substrings from a collection of string values in a table.
CONCAT() - Concatenates two or more strings.
RAND() - Generates a random collection of numbers of given length.
ROUND() - Calculates the round off integer value for a numeric field (or decimal
point values).
NOW() - Returns the current data & time.
FORMAT() - Sets the format to display a collection of values.
The user-defined functions in SQL are like functions in any other programming
language that accept parameters, perform complex calculations, and return a value.
They are written to use the logic repetitively whenever required. There are two types
of SQL user-defined functions:
What is User-defined function? What are its Scalar Function: As explained earlier, user-defined scalar functions return a single
various types? scalar value.
Table Valued Functions: User-defined table-valued functions return a table as
output.Inline: returns a table data type based on a single SELECT statement.Multi-
statement: returns a tabular result-set but, unlike inline, multiple SELECT statements
can be used inside the function body.
Collation refers to a set of rules that determine how data is sorted and compared.
Rules defining the correct character sequence are used to sort the character data. It
incorporates options for specifying case-sensitivity, accent marks, kana character
types and character width. Below are the different types of collation sensitivity:
What is Collation? What are the different Case sensitivity: A and a are treated differently.
types of Collation Sensitivity? Accent sensitivity: a and á are treated differently.
Kana sensitivity: Japanese kana characters Hiragana and Katakana are treated
differently.
Width sensitivity: Same character represented in single-byte (half-width) and double-
byte (full-width) are treated differently.
Creating empty tables with the same structure can be done smartly by fetching the
records of one table into a new table using the INTO operator while fixing a WHERE
clause to be false for all records. Hence, SQL prepares the new table with a duplicate
How to create empty tables with the same structure to accept the fetched records but since no records get fetched due to the
structure as another table? WHERE clause in action, nothing is inserted into the new table.