Basic Level SQL Interview Questions
Basic Level SQL Interview Questions
Basic Level SQL Interview Questions
SQL MySQL
Q3. What do you mean by DBMS? What are its different types?
A Database Management System (DBMS) is a software application that interacts with the
user, applications, and the database itself to capture and analyze data. A database is a structured
collection of data.
A DBMS allows a user to interact with the database. The data stored in the database can be
modified, retrieved and deleted and can be of any type like strings, numbers, images, etc.
There are two types of DBMS:
Relational Database Management System: The data is stored in relations (tables).
Example – MySQL.
Non-Relational Database Management System: There is no concept of relations, tuples
and attributes. Example – MongoDB
A Primary key in SQL is a column (or collection of columns) or a set of columns that
uniquely identifies each row in the table.
Uniquely identifies a single row in the table
Null values not allowed
Example- In the Student table, Stu_ID is the primary key.
Delete command is used to delete a row in a Truncate is used to delete all the rows from a
table. table.
You can rollback data after using delete
You cannot rollback data.
statement.
It is a DML command. It is a DDL command.
It is slower than truncate statement. It is faster.
Q13. What is the difference between clustered and non-clustered index in SQL?
The differences between the clustered and non clustered index in SQL are :
1. Clustered index is used for easy retrieval of data from the database and its faster whereas
reading from non clustered index is relatively slower.
2. Clustered index alters the way records are stored in a database as it sorts out rows by the
column which is set to be clustered index whereas in a non clustered index, it does not
alter the way it was stored but it creates a separate object within a table which points back
to the original table rows after searching.
3. One table can only have one clustered index whereas it can have many non clustered
index.
Q18. What is an Index?
An index refers to a performance tuning method of allowing faster retrieval of records from the
table. An index creates an entry for each value and hence it will be faster to retrieve data.
Q27. What is the difference between cross join and natural join?
The cross join produces the cross product or Cartesian product of two tables whereas the natural
join is based on all the columns having the same name and data types in both the tables.
Apart from this SQL Interview Questions Blog, if you want to get trained from professionals on
this technology, you can opt for structured training from edureka!
Q31. Write a SQL query to find the names of employees that begin with ‘A’?
To display name of the employees that begin with ‘A’, type in the below command:
1 SELECT * FROM Table_name WHERE EmpName like 'A%'
Q32. Write a SQL query to get the third-highest salary of an employee from
employee_table?
Q35. How can you insert NULL values in a column while inserting the data?
NULL values in SQL can be inserted in the following ways:
Implicitly by omitting column from column list.
Explicitly by specifying NULL keyword in the VALUES clause
Q36. What is the main difference between ‘BETWEEN’ and ‘IN’ condition operators?
BETWEEN operator is used to display rows based on a range of values in a row whereas the IN
condition operator is used to check for values contained in a specific set of values.
Example of BETWEEN:
SELECT * FROM Students where ROLL_NO BETWEEN 10 AND 50;
Example of IN:
SELECT * FROM students where ROLL_NO IN (8,15,25);
Q41. What is the difference between ‘HAVING’ CLAUSE and a ‘WHERE’ CLAUSE?
HAVING clause can be used only with SELECT statement. It is usually used in a GROUP BY
clause and whenever GROUP BY is not used, HAVING behaves like a WHERE clause.
Having Clause is only used with the GROUP BY function in a query whereas WHERE Clause is
applied to each row before they are a part of the GROUP BY function in a query.
Apart from this SQL Interview Questions blog, if you want to get trained from professionals on
this technology, you can opt for a structured training from edureka! Click below to know more.
Q64. What are the different authentication modes in SQL Server? How can it be changed?
Windows mode and Mixed Mode – SQL and Windows. You can go to the below steps to change
authentication mode in SQL Server:
Click Start> Programs> Microsoft SQL Server and click SQL Enterprise Manager to run
SQL Enterprise Manager from the Microsoft SQL Server program group.
Then select the server from the Tools menu.
Select SQL Server Configuration Properties, and choose the Security page.
1 SELECT FIRST(Marks)
2 FROM Students;
Output:
1
LAST()
Used to return the last value of the column which you choose.
Syntax:
1 SELECT LAST(ColumnName)
2 FROM TableName;
Example:
Write a query to retrieve the marks of the last student.
1 SELECT LAST(Marks)
2 FROM Students;
Output: 92
Well, with that we come to an end to SQL Aggregate Functions. Next in this article on SQL
Functions, let us understand the various Scalar Functions.
Scalar SQL Functions
The Scalar Functions in SQL are used to return a single value from the given input
value. Following are a few of the most commonly used Aggregate Functions:
Let us look into each one of the above functions in depth.
Function Description
Used to convert string column values to
LCASE()
lowercase
This function is used to convert a string column
UCASE()
values to Uppercase.
Returns the length of the text values in the
LEN()
column.
Extracts substrings in SQL from column values
MID()
having String data type.
Rounds off a numeric value to the nearest
ROUND()
integer.
This function is used to return the current
NOW()
system date and time.
FORMAT() Used to format how a field must be displayed.
LCASE()
Used to convert values of a string column to lowercase characters.
Syntax:
1 SELECT LCASE(ColumnName)
2 FROM TableName;
Example:
Write a query to retrieve the names of all students in lowercase.
1 SELECT LCASE(StudentName)
2 FROM Students;
Output:
1 sanjay
2 varun
3 akash
4 rohit
5 anjali
UCASE()
Used to convert values of a string column to uppercase characters.
Syntax:
1 SELECT UCASE(ColumnName)
2 FROM TableName;
Example:
Write a query to retrieve the names of all students in lowercase.
1 SELECT UCASE(StudentName)
2 FROM Students;
Output:
1 SANJAY
2 VARUN
3 AKASH
4 ROHIT
5 ANJALI
LEN()
Used to retrieve the length of the input string.
Syntax:
1 SELECT LENGTH(String) AS SampleColumn;
Example:
Write a query to extract the length of the student name “Sanjay”.
1 SELECT LENGTH(“Sanjay”) AS StudentNameLen;
Output:
1 6
MID()
This function is used to extract substrings from columns having string data type.
Syntax:
1 SELECT MID(ColumnName, Start, Length)
2 FROM TableName;
Example:
Write a query to extract substrings from the StudentName column.
1 SELECT MID(StudentName, 2, 3)
2 FROM Students;
Output:
1 anj
2 aru
3 kas
4 ohi
5 nja
ROUND()
This function is used to round off a numeric value to the nearest integer.
Syntax:
Example:
For this example, let us consider the following Marks table in the Students table.
StudentID StudentName Marks
1 Sanjay 90.76
2 Varun 80.45
3 Akash 54.32
4 Rohit 72.89
5 Anjali 67.66
Write a query to round the marks to the integer value.
1 SELECT ROUND(Marks)
2 FROM Students;
Output:
1 91
2 80
3 54
4 73
5 68
NOW()
Used to return the current date and time. The date and time are returned in the “YYYY-MM-DD
HH-MM-SS” format.
Syntax:
1 SELECT NOW();
Example:
Write a query to retrieve the current date and time.
SELECT NOW();
Output:
NOW()
2019-10-14 09:16:36
FORMAT()
This function formats the way a field must be displayed.
Syntax:
FORMAT(InputValue, Format)
Example:
Write a query to display the numbers “123456789” in the format “###-###-###”
SELECT FORMAT(123456789, “###-###-###”);
Output:
123-456-789