Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
To become proficient in SQL, however, remote developers should really take their time to study this field — and test their knowledge via technical interviews.
SQL, or Structured Query Language, is an indispensable tool for organizing data: while front-end frameworks like Angular, React, and Vue.js (each of them is closely tied to JavaScript: check out our JS interview questions Part 1 and Part 2!) work on the magic of interacting with a web app, SQL manages does the dirty work — ensuring that all the precious data is structured accordingly.
SQL proficiency, therefore, is crucial in many areas: analytics, data science, back-end, marketing, research — and SQL developers work on truly great projects. To become proficient in SQL, however, remote developers should really take their time to study this field — and test their knowledge via technical interviews. In this article, we will explore some of the best SQL interview questions that you can study for your next technical interview.
A broad topic like organizing data in an efficient way requires some theoretical questions — with these, you can assess your fundamental database knowledge.
First of all, it is crucial to analyse the difference between SQL and noSQL systems. It comes down to:
These terms encompass different SQL commands which are used, as their names suggest, to either define, manipulate, or control data.
CREATE, ALTER, TRUNCATE, DROP
, and RENAME
.GRANT
and REVOKE
in the SQL Query.SELECT, INSERT, DELETE
and UPDATE
.These are the DDL commands available in SQL:
CREATE
: creates a new table, a view of a table, or other object in database.ALTER
: modifies an existing database object, such as a table.DROP
: deletes an entire table, a view of a table or other object in the database.TRUNCATE
: removes all records (and spaces associated with them) from a table.COMMENT
: adds comments to the data dictionary.RENAME
: renames an object.These are the DML commands available in SQL:
SELECT
: retrieves certain records from one or more tables.INSERT
: creates a record.UPDATE
: modifies records.DELETE
: deletes records.MERGE — UPSERT
operation: MERGE statements are used to INSERT
new records or UPDATE
existing ones.CALL
: calls a PL/SQL, or Java subprogramEXPLAIN PLAN
: interprets data access path.LOCK TABLE
: utilizes Concurrency Control.These are the DCL commands available in SQL:
GRANT
: gives a privilege to user.REVOKE
: takes privileges granted from user back.In a database, transactions are logical units which are executed independently to retrieve data or update it. In relational databases, the ACID acronym is used to denote the qualities of database transactions: Atomic, Consistent, Isolated, and Durable.
One of the requirements of relational databases is support for ACID transactions; as mentioned earlier, C denotes Consistency — this means that in case of disconnected nodes all transactions will be refused. According to the CAP theorem, it is impossible for a distributed data store to provide all of these features:
When an incident like network failure occurs, a distributed system can either:
Due to the nature of relational databases, option B is optimal. With scaling, the chance of partitioning (i.e. nodes failing to communicate) increases, resulting in the dilemma described above.
To scale relational databases effectively, we need to examine how the data is modeled: for instance, in a normalized database with heavily inter-related data, sharding becomes increasingly difficult. In essence, the problem of scaling is dependent on our application’s capacity to be divided into components/clusters. Major companies are all trying to address this issue: Oracle and MySQL provide tools for scaling, Postgres offers some extensions, and Google even created a database service that, as the company claims, is built for the cloud specifically to combine the benefits of relational database structure with non-relational horizontal scale.
There are a few solutions to the scaling problem (although they are not perfect):
Indexes are database objects designed to improve query performance. By applying indexes to one or more columns in table or views, we could improve data retrieval time from these tables. Index hunting helps in improving the speed as well as the query performance of the database. This can be achieved via the following measures:
Now it’s time for the next group of challenges: coding! In these exercises, you can test if you’ve got what it takes to become the best remote SQL developer. (We will use MySQL syntax as it’s the most common one)
Answer:
CREATE TABLE IF NOT EXISTS `developers` ( `id` INT NOT NULL AUTO_INCREMENT, `first_name` VARCHAR(20) NOT NULL, `last_name` VARCHAR(25) NOT NULL, `hire_date` DATE NOT NULL, `position` VARCHAR(10) NOT NULL DEFAULT 'backend', `salary` DECIMAL(8,2) NULL DEFAULT NULL, PRIMARY KEY (`id`), INDEX `DEV_POS_IX` (`position` ASC), INDEX `DEV_NAME_IX` (`last_name` ASC, `first_name` ASC)) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8
SELECT first_name, last_name, round(salary/12,2) as 'monthly salary' FROM developers;
SELECT MAX(salary) FROM developers WHERE position='backend';
SELECT DISTINCT salary FROM developers d1 WHERE 5 = (SELECT COUNT(DISTINCT salary) FROM developers d2 WHERE d2.salary >= d1.salary);
SELECT d1.first_name, d1.last_name, d1.hire_date FROM developers d1 JOIN developers d2 ON (d2.last_name = 'Wilson') WHERE d2.hire_date < d1.hire_date;
Organizing and structuring data may not seem “hip” or “cool” as designing modern web applications, but any SQL developer will tell you: these are just different forms of art. By the way, SQL developers might have much more power than their front-end counterparts: just look what one database error can do!