Database Administration Q and A
Database Administration Q and A
System database administrator: This role focuses on system administration and doesn’t typically handle
database applications. They often install, configure, upgrade and patch database software to keep the
overall system running well.
Application database administrator: This person focuses on integrating databases into applications,
often using SQL in the process.
Performance database administrator: This type of database administrator optimizes various databases,
using physical and virtual hardware in the best way possible to make data access easier.
Task-oriented database administrator: Some database administrators focus on one very specific
database-related task. Examples include backups for data recovery, compliance and security.
What is SQL?
Structured Query Language is a domain-specific language used in programming and designed for
managing data held in a relational database management system, or for stream processing in a
relational data stream.
It is used in programming and managing data held in relational database management systems such as
MySql, MS SQL Server, oracle Sybase, etc as a medium (instructions) for accessing and interacting with
data.
It enables performing several operations such as creating, deleting, modifying, and fetching entries in
the database and some other advanced statistical, arithmetic, and mathematical operations. Let us try
understanding the basics of SQL now.
DDL(Data Definition Language): To make/perform changes to the physical structure of any table residing
inside a database, DDL is used. These commands when executed are auto-commit in nature and all the
changes in the table are reflected and saved immediately.
DML(Data Manipulation Language): Once the tables are created and the database is generated using
DDL commands, manipulation inside those tables and databases is done using DML commands. The
advantage of using DML commands is, that if in case any wrong changes or values are made, they can be
changed and rolled back easily.
DQL(Data Query Language): Data query language consists of only one command upon which data
selection in SQL relies. The SELECT command in combination with other SQL clauses is used to retrieve
and fetch data from databases/tables based on certain conditions applied by the user.
DCL(Data Control Language): DCL commands as the name suggests manage the matters and issues
related to the data controller in any database. DCL includes commands such as GRANT and REVOKE
which mainly deal with the rights, permissions, and other controls of the database system.
TCL(Transaction Control Language): Transaction Control Language as the name suggests manages the
issues and matters related to the transactions in any database. They are used to roll back or commit the
changes in the database.
Data Definition Language
In SQL DDL commands are used to create and modify the structure of a database and database
objects. These commands are CREATE, DROP, ALTER, TRUNCATE, and RENAME. Let
us discuss these commands one at a time.
CREATE
Creates a database named 'database_name'. Let us create our own database and table which we
will use as a reference throughout this article:
This creates a new table with the name 'table_name' in our database. It will have N columns for
each of the same datatypes as mentioned adjacent to it in the create syntax.
For instance:
This creates an empty table. For clarity suppose we add an entry (row) in the column (as in the
image) the result will be:
first_name age
myFirstName 20
DROP
To drop a table:
DROP TABLE table_name;
Output:
To drop a database:
This removes the database named 'database_name' if present. Suppose we try this with our
database, the result looks like this:
Output:
ALTER
Output:
| first_name | age |
|:-----------:|:---:|
| myFirstName | 20 |
In the above example, we are adding a column to our table. Apart from that, we can perform
other operations such as dropping a column, modifying it, etc.
To change the properties of a column such as its type, type capacity, add constraints, etc:
ALTER TABLE table_name
ALTER COLUMN column_name column_type;
Output:
Similarly, we can drop a column using alter with the following syntax:
Output:
TRUNCATE
This command is similar to the drop table command. The only difference is that while the drop
command removes the table as well as its contents, the truncate command only erases the
contents of the table's contents and not the table itself. Let us take an example to be clearer:
Output:
As shown in the image above, truncate has removed the contents of the table. The table, though
now empty, still exists. Think of truncating a table as emptying it rather than deleting it.
RENAME
This command is used to change the name of an existing table. The syntax is
RENAME TABLE table_name TO table_name_new;
The following image shows how to rename our table from 'my_table' to 'some_table':
Output:
INSERT
Insert statement is used to insert data in a SQL table. Using the Insert query, we can add one or
more rows to the table. Following is the syntax of the MySQL INSERT Statement.
Let's take a quick instance for understanding this better. Suppose that we need to insert 2
rows {"myName3", 2, true} and {"myName4", 28, false}. This is how we would accomplish
that:
Output:
We don't necessarily have to include all column values. We can for example omit the age column
as shown below:
Output:
UPDATE
This command is used to make changes to the data in the table. Its syntax is:
UPDATE table_name
SET column1 = val1,
column2 = val2,
...
WHERE CLAUSE;
How about we update the employment status of myName of age 12 which has it as NULL? This
is how we achieve it:
update my_table
set employed=true
where age=12;
Output:
Let's batch-update all our rows without filtering them on any condition. Suppose we want to
increment the value of every row in the age column. The following query is what we need:
update my_table
set age = age + 1;
Output:
DELETE
This command is used to remove a row from a table. the syntax for delete is
The where clause is optional. To delete the row with first_name "myName5 run this query:
Output:
Select is one of the most important SQL commands. It is used to retrieve data from a database.
One can fetch either the entire table or some data according to specified rules.
The data returned is stored in a result table. With the SELECT clause of a SELECT command
statement, we specify the columns that we want to be displayed in the query result and,
optionally, which column headings we prefer to see above the result table.
The select clause is the first clause and is one of the last clauses of the select statement that the
database server evaluates. The reason for this is that before we can determine what to include in
the final result set, we need to know all of the possible columns that could be included in the
final result set.
SELECT column1 as c1
column2 as c2
...
from table_name;
'as c1' implies that the result table column that holds the data from column1 of the original table,
will be identified as 'c1' and its usage is optional.
To get the age of all our rows, we would run the first of the following query:
Output:
| myAge |
| ----- |
| 47 |
Firstly there's an asterisk in place of specifying a column. What it does is signal to the DBMS
that the user has requested all the data in the table, i.e. entry of every column for every row.
Therefore the entire table is returned as it is.
Secondly, we haven't used the operator here. thus the returned table columns have retained their
original labels.
We can select data as per our requirements by filtering. We have an array of methods, operators,
functions, etc for this purpose. Suppose we need to fetch only those rows which qualify a certain
criterion. We use a 'where' clause to fulfill this.
Assume the present state of our table is as shown in the image below.
Output:
Let's say that we need to fetch all rows where the age is strictly greater than 20. The query that
we need is as follows:
select * from
my_table where age>20;
Output:
yes; it works!
To extract all the rows where the name matches a certain pattern we use the 'like' operator. The
following snippet shows its action:
select * from my_table
where first_name like "myName_";
Output:
'like' is an operator used for pattern matching. It uses two special characters embedded in the
string to be matched; The percent sign '%' represents zero, one, or any number of characters,
while the underscore sign '_' represents a single character.
In the previous example, we used underscore, and therefore all rows except the first were
returned because 'myName_' implies a matching string of the form 'myName' + an additional
character. The last 3 strings are of this form and hence are matched, unlike the first one which
does not have any additional character present at last.
Similarly, we can obtain all the rows in the first_name field which ends with zero ('0').
Output:
It provides the administrators, to remove and set database permissions to desired users as needed.
These commands are employed to grant, remove and deny permissions to users for retrieving and
manipulating a database. There are two relevant commands under this category: grant and
revoke.
GRANT
GRANT is a command used to provide access or privileges on the database objects to the users.
SYNTAX
GRANT PRIVILEGES
ON OBJECT
TO USER;
1. SELECT:
To grant Select Privilege to a table named “tableName", the user name is "userName",
and the following GRANT statement should be executed.
GRANT SELECT
ON tableName
TO 'userName'@'localhost';
To Grant all the privileges to a user named “userName” in a table “tableName”, the
following Grant statement should be executed.
GRANT ALL
ON tableName
TO 'userName'@'localhost';
GRANT SELECT
ON tableName
TO '*'@'localhost';
REVOKE
Once you have granted privileges, you may need to revoke some or all of these privileges. To do
this, you can run a revoke command. You can revoke any combination of SELECT, INSERT,
UPDATE, DELETE, REFERENCES, ALTER, or ALL.
REVOKE privileges
ON object
FROM user;
Object is the name of the database object that you are revoking privileges for. In the case of
revoking privileges on a table, this would be the table name. Username of the user that will have
these privileges revoked.
Suppose we need to revoke delete permission for the 'tableName' table' from a user named
'userNamed', the following would be the query.
REVOKE DELETE
ON tableName
FROM userName;
REVOKE ALL
ON tableName
FROM userName;
COMMIT: It's a SQL command used in the transaction tables or database to make the
current transaction or database statement permanent. It shows the successful completion
of a transaction. If we have successfully executed the transaction statement or a simple
database query, we want to make the changes permanent. We need to perform the commit
command to save the changes, and these changes become permanent for all users.
Furthermore, once the commit command is executed in the database, we cannot regain its
previous states in which it was earlier before the execution of the first statement.
SYNTAX
commit;
ROLLBACK: Undoes any changes made to the database. ROLLBACK is the SQL
command that is used for reverting changes performed by a transaction. When a
ROLLBACK command is issued it reverts all the changes since the last COMMIT or
ROLLBACK.
SYNTAX
ROLLBACK;
SAVEPOINT: This command creates a point in your transaction to which you can roll
back. It is a command in SQL that is used with the rollback command. It is a command in
Transaction Control Language that is used to mark the transaction in a table.
SYNTAX
SAVEPOINT some_name;
Conclusion
SQL is used in programming and designed for managing data held in a relational
database management system, or for stream processing in a relational data stream.
The various database management systems that use SQL as a medium are MySql,
MariaDB, PostgreSQL, etc.
Based on functionalities performed by them, there are five types of SQL
Commands- DDL(Data Definition Language), DML(Data Manipulation
Language), DQL(Data Query Language), TCL(Transaction Control
Language), DCL(Data Control Language).
In SQL DDL commands are used to create and modify the structure of a database and
database objects. These commands are CREATE, DROP, ALTER, TRUNCATE,
and RENAME. Let's discuss these commands one at a time.
DML is used for inserting, deleting, and updating data in a database. It is used to retrieve
and manipulate data in a relational database. It includes INSERT, UPDATE,
and DELETE. Let's discuss these commands one at a time.
DQL commands are used for fetching data from a relational database. The only one
command, ‘SELECT’ is equivalent to the projection operation in relational algebra. This
command selects the attribute based on the condition described by the WHERE clause
and returns them.
DCL is used to access the stored data. It is used to revoke and grant the user the required
access to a database. In the database, this language does not have the feature of rollback.
It is a part of the structured query language (SQL).
TCL includes statements that are used to manage the changes that are made from DML
statements. It enhances the transactional nature of SQL. The TCL commands in SQL
are COMMIT and ROLLBACK.
Integrity Constraints in Database Management Systems are the set of pre-defined rules responsible for
maintaining the quality and consistency of data in the database.
Domain Constraint
Domain integrity constraint contains a certain set of rules or conditions to restrict the kind of
attributes or values a column can hold in the database table. The data type of a domain can be string,
integer, character, DateTime, currency, etc.
Example:
Consider a Student's table having Roll No, Name, Age, Class of students.
101 Adam 14 6
102 Steve 16 8
103 David 8 4
104 Bruce 18 12
105 Tim 6 A
In the above student's table, the value A in the last row last column violates the domain integrity
constraint because the Class attribute contains only integer values while A is a character.
Domain Constraint
Domain integrity constraint contains a certain set of rules or conditions to restrict the kind of
attributes or values a column can hold in the database table. The data type of a domain can be string,
integer, character, DateTime, currency, etc.
Example:
Consider a Student's table having Roll No, Name, Age, Class of students.
101 Adam 14 6
102 Steve 16 8
103 David 8 4
104 Bruce 18 12
105 Tim 6 A
In the above student's table, the value A in the last row last column violates the domain integrity
constraint because the Class attribute contains only integer values while A is a character.
Q:
A:
Many types of database infrastructure exist, so you want to confirm that the applicant has the
background that you’re looking for. Look for people who mention the specific database versions
they’re familiar with, as well as a brief explanation of their experience level with each.
What to look for:
Detailed information
Years of experience
Example:
“I’m most familiar with Microsoft SQL Server. I started with the 2012 version and worked with that for
five years. I’ve also supported SQL Server 2014 and 2016 environments, as well as MongoDB.
Q:
A:
Many organizations are moving from a fully on-premises infrastructure to the cloud. You can discover
which environment your candidate works the best in. If your organization intends on changing away
from your current configuration, you can find out whether your interviewee can support your long-
term goals.
What to look for:
Flexibility
Willingness to learn
Example:
“I have ten years of experience with on-premises databases, and I’m currently working on
certifications for hybrid and cloud-based infrastructure. I do my best to keep on top of the latest
trends in database administration and educate myself appropriately.
Q:
A:
This question tests the technical knowledge of your applicant and is directed at people you’re hiring
for mid-level positions. Look for an answer that covers the basic concept and goes into some detail
about its role in a database environment.
What to look for:
Good communication
Example:
“Open Database Connectivity is a method used by application front ends when they’re communicating
with a database backend. I’ve helped software developers implement ODBC so they can pull the right
data sources into custom enterprise apps.
Q:
What is the highest number of database servers you have worked with?
A:
You get an idea of how large of a data center the database administrator has worked with. If you’re a
large organization looking for a DBA for critical systems, the applicant with small business experience
may not work out well.
Size of company
Number of servers
Example:
“I worked with 200 Oracle on-premises databases in a mid-size professional services organization and
have experience scaling this environment up and down as needed.”
Q:
A:
Data loss is a high-pressure situation for a database administrator, especially if a migration project
falls behind schedule. You get to see their thought process, how they handle stress and the strategies
they use for disaster recovery.
What to look for:
Level-headed reactions
Example:
“I would step in and identify whether the problem that causes the data loss was a one-time
occurrence or an issue with the entire migration. Once I addressed that, I would locate the backup
containing those databases and begin the restoration process.”
Q:
A:
Big data technology is another rapidly growing area. Hadoop helps organizations work with massive
data sets by splitting them into smaller sets and then consolidating the results. A willingness to learn
Hadoop or existing experience may help your company use your data more efficiently.
What to look for:
Overall experience
Example:
“I have experience implementing and optimizing Hadoop solutions for enterprises. I also stay on top
of new ways to use Hadoop by participating in technical forums and a Hadoop Slack channel.
Q:
A:
A database administrator needs a strong process for identifying and addressing issues. While
automated tools help lighten their load, you get to see their overall thought process and
troubleshooting strategy with this answer.
What to look for:
Solid process
Example:
“I use a combination of manual and proactive monitoring to keep an eye on the database servers. I
regularly check tickets to see if anyone is reporting performance issues or other concerns. When I
identify something that requires troubleshooting, I begin by diagnosing the symptoms and probable
causes. I will delegate the hands-on repair to a lower-level tech if needed, depending on my task list
and the complexity of the repair.”
Q:
Have you ever lost significant amounts of data while on the job? What was your process for handling
this?
A:
Losing company data is typically an unfortunate, but common occurrence that can happen to
database administrators. This answer should help interviewers understand how the candidate
handles this situation and if they have a process in place to successfully recover this data. Database
administrators are expected to act quickly and logically in this high-pressure situation to ensure
significant pieces of data are recovered and secured.
Example:
"I was once working on a data migration project and was in charge of conducting a test migration.
When I conducted the test, I realized that several pieces of our data were either lost or corrupted. I
decided to troubleshoot the issue to find more specific reasons this problem was occurring. I realized
that there were several outdated systems that were getting lost in the file updates. Luckily, I had
downloaded a high-quality backup program to recover these lost files and took note of this issue to
ensure the corruption and loss of these data files wouldn't take place again."
1. How would you transfer data from MySQL to Microsoft SQL Server?
This question assesses the candidate’s experience and knowledge in data migration between different
database systems.
Sample answer:
“I would use a combination of tools like SSIS (SQL Server Integration Services) and scripts to transfer
data. First, I’d analyze the schema in both databases to identify any compatibility issues. Then, I’d
proceed with the data transfer, ensuring data integrity is maintained.”
This question gauges the candidate’s understanding of best practices in database management.
Sample answer:
“No, running tests on a live database is risky and not recommended. I would use a staging
environment that mimics the live database for all testing purposes.”
3. What measurements would you take to protect our databases from external threats?
Sample answer:
“I would implement multiple layers of security such as firewalls, encryption, and regular audits. I’d
also restrict user permissions to limit data exposure.”
4. We are building a new database for our employee records. How do you define system storage
requirements?
This question tests the candidate’s ability to plan and implement new databases.
Sample answer:
“I would start by estimating the volume of data, considering growth over time. Then, I’d look into the
types of queries and transactions to determine the required performance. Based on these factors, I’d
define the storage requirements.”
Sample answer:
“I would perform regular audits and tests, at least quarterly, to ensure that all security measures are
effective and up-to-date.”
6. Are you familiar with SQL? Name the most useful SQL queries and their roles.
This question assesses the candidate’s familiarity with SQL, a fundamental skill for any DBA.
Sample answer:
“Yes, I am familiar with SQL. The most useful queries include SELECT for data retrieval, INSERT for
adding new records, UPDATE for modifying existing data, and DELETE for removing records. These are
the CRUD operations essential for database management.”
This question tests the candidate’s understanding of different types of database models.
Sample answer:
“Navigational databases use pointers to navigate through data, while relational databases use tables
to define relationships between data. Relational databases are more flexible and easier to query.”
8. Can you provide an example of where you can or should use a foreign key?
This question evaluates the candidate’s understanding of database relationships and integrity.
Sample answer:
“A foreign key is used to establish a relationship between two tables. For example, in a database
containing ‘Employees’ and ‘Departments’ tables, the ‘DepartmentID’ in the ‘Employees’ table could
be a foreign key referencing ‘Departments.'”
This question gauges the candidate’s familiarity with database-specific SQL extensions.
Sample answer:
“T-SQL is an extension of SQL for Microsoft SQL Server, while PL/SQL is for Oracle databases. Both
offer procedural programming features, but they have different syntax and capabilities.”
This question assesses the candidate’s ability to monitor and maintain database health.
Sample answer:
“I would look at several factors like CPU usage, memory usage, and query performance. Regular logs
and alerts also provide valuable information. If all these are within optimal levels, the server is likely
running properly.”