0% found this document useful (0 votes)
54 views100 pages

SQL Part 1

SQL is a query language used to interact with databases. It allows users to extract, modify, and update data. SQL is widely used across industries to query databases and find valuable insights from stored employee records and other data. Common SQL tasks include creating tables, deleting rows, updating data, and joining tables to extract related information.

Uploaded by

Jai Deep
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
54 views100 pages

SQL Part 1

SQL is a query language used to interact with databases. It allows users to extract, modify, and update data. SQL is widely used across industries to query databases and find valuable insights from stored employee records and other data. Common SQL tasks include creating tables, deleting rows, updating data, and joining tables to extract related information.

Uploaded by

Jai Deep
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 100

SQL interview

questions
SQL stands for Structured Query
Language. It is the primary language to
interact with databases. With the help
of SQL, we can extract data from a
Question 1
database, modify this data and also
update it whenever there is a
What is requirement. This query language is
evergreen and is widely used across
SQL? industries. For example, if a company
has records of all the details of their
employees in the database. With the
help of SQL, all of this data can be
queried to find out valuable insights in a
short span of time.
SQL stands for Structured Query
Language. It is the primary language to
interact with databases. With the help
of SQL, we can extract data from a
Question 2
database, modify this data and also
update it whenever there is a
How to requirement. This query language is
evergreen and is widely used across
create a industries. For example, if a company
has records of all the details of their
table in employees in the database. With the
help of SQL, all of this data can be
SQL? queried to find out valuable insights in a
short span of time.
There are two ways to delete a table
from sql: DROP and TRUNCATE. The
DROP TABLE command is used to
completely delete the table from the
Question 3
database. This is the command:
DROP TABLE table_name;
How to The above command will completely
delete all the data present in the table
delete a along with the table itself.
But if we want to delete only the data
table in present in the table but not the table
itself, then we will use the truncate
SQL? command:
DROP TABLE table_name ;
Question 4

How to
change a
table name
in SQL?
Question 5

How to
delete a
row in
SQL?
A database is a repository in sql, which
can comprise of multiple tables.

This will be the command to create a


Question 6
database in sql:

How to CREATE DATABASE database_name.

create a
database in
SQL?
Normalization is used to decompose a
Question 7
larger, complex table into simple and
smaller ones. This helps us in removing
What is all the redundant data.
Normalizati
-on in SQL?
Question 8

What is join
in SQL?
Question 9
SQL Server comes under the
What is category of Relational database
management system.
SQL
server?
Question 10

How to
insert date
in SQL?
Question 11

What is Primary Key is a constraint in SQL.


So, before understanding what
Primary exactly is a primary key, let’s
understand what exactly is a
Key in SQL? constraint in SQL.
Question 12

How do I To view tables in SQL, all you need to


do is give this command:
view tables Show tables;
in SQL?
Question 13

What is PL SQL stands for Procedural


language constructs for Structured
PL/SQL Query Language.
Question 14

What is
MYSQL?
Question 15

How can I
see all
tables in
SQL?
Question 16

What is ETL stands for Extract, Transform


and Load. It is a three step process
ETL in
SQL?
Question 17

How to
install
SQL?
Question 18

What is the
update
command in
SQL?
Question 19

How to When it comes to SQL Server, it is not


possible to rename the column with
rename the help of ALTER TABLE command,
we would have to use sp_rename.
column
name in SQL
Server?
Question 20

What are
the types
of SQL
Queries?
Question 21

Write a Query
to display the SELECT region, COUNT(gender)
number of FROM employee GROUP BY region;
employees
working in each
region?
Question 22

What are Triggers may implement DML by


using INSERT, UPDATE, and DELETE
Nested
statements. These triggers that
Triggers? contain DML and find other triggers
for data modification are called
Nested Triggers.
Question 23

Write SQL By using BETWEEN in the where


query to fetch clause, we can retrieve the Employee
employee names Ids of employees with salary >=
20000and <=10000. SELECT
having a salary FullName FROM EmployeeDetails
greater than or WHERE EmpId IN (SELECT EmpId
equal to 20000 FROM EmployeeSalary WHERE Salary
and less than or BETWEEN 5000 AND 10000)
equal 10000.
Question 24

Given a table “Order by 2” is valid when there are at


Employee having least 2 columns used in SELECT
columns empName statement. Here this query will throw
and empId, what will error because only one column is
be the result of the used in the SELECT statement.
SQL query below?
select empName
from Employee
order by 2 asc;
Question 25

What is OLTP? OLTP stands for Online Transaction


Processing. And is a class of software
applications capable of supporting
transaction-oriented programs. An
essential attribute of an OLTP system
is its ability to maintain concurrency.
Question 26 Data Integrity is the assurance of
accuracy and consistency of data
What is Data
over its entire life-cycle, and is a
Integrity?
critical aspect to the design,
implementation and usage of any
system which stores, processes, or
retrieves data. It also defines integrity
constraints to enforce business rules
on the data when it is entered into an
application or a database.
Question 27 OLAP stands for Online Analytical
Processing. And a class of software
What is OLAP?
programs which are characterized by
relatively low frequency of online
transactions. Queries are often too
complex and involve a bunch of
aggregations.
Question 28
There are so many times where user
Find the Constraint needs to find out the specific
information from constraint information of the table.
the table? following queries are useful, SELECT *
From User_Constraints; SELECT *
FROM User_Cons_Columns;
Question 29
Select distinct
Can you get the list e.empid,e.empname,e.salary from
of employees with employee e, employee e1 where
same salary? e.salary =e1.salary and e.empid !=
e1.empid
Question 30

What is an
alternative for
TOP clause in SQL?
Question 31

Will following
Error. Operand data type NULL is
statement give
invalid for Avg operator.
error or 0 as
output? SELECT
AVG (NULL)
Question 32

What is the
The output of Cross Join is called a
Cartesian product
Cartesian product. It returns rows
of the table?
combining each row from the first
table with each row of the second
table. For Example, if we join two
tables having 15 and 20 columns the
Cartesian product of two tables will
be 15×20=300 rows.
Question 33

What is a schema in
schema is blueprint for the database
SQL?
Question 34

What is the WHERE


The ‘Where’ clause is used to extract
clause in SQL?
elements from the table on the basis
of a condition.
Question 35

How to delete a
To delete a column in SQL we will be
column in SQL?
using DROP COLUMN method:
ALTER TABLE employees
DROP COLUMN age;
Question 36

What is a unique
Unique Key is a constraint in SQL.
key in SQL?
Question 37

How to implement
We can implement multiple
multiple conditions
conditions using AND, OR operators:
using WHERE
SELECT * FROM employees WHERE
clause?
first_name = ‘Steven’ AND salary
<=10000;
Question 38 SQL injection is a hacking technique
which is widely used by black-hat
What is SQL hackers to steal data from your tables
injection? or databases. Let’s say, if you go to a
website and give in your user
information and password, the
hacker would add some malicious
code over there such that, he can get
the user information and password
directly from the database.
Question 39

What is a trigger in A trigger is a stored program in a


SQL? database which automatically gives
responses to an event of DML
operations done by insert, update, or
delete.
Question 40

How to insert
multiple rows in
SQL?
Question 41

How to find the nth


highest salary in
SQL?
Question 42

How to copy table We can use the SELECT INTO


in SQL? statement to copy data from one
table to another. Either we can copy
all the data or only some specific
columns.
Question 43

How to add a new We can add a new column in SQL


column in SQL? with the help of alter command:
ALTER TABLE employees ADD
COLUMN contact INT(10);
Question 44

How to use LIKE in The LIKE operator checks if an


SQL? attribute value matches a given string
pattern. Here is an example of LIKE
operator
SELECT * FROM employees WHERE
first_name like ‘Steven’;
Question 45

If we drop a table, Yes, SQL server drops all related


does it also drop objects, which exists inside a table like
related objects like constraints, indexex, columns,
constraints, defaults etc. But dropping a table will
indexes, columns, not drop views and sorted
default, views and procedures as they exist outside the
sorted table.
procedures?
Question 46

Can we disable a Yes, we can disable a single trigger on


trigger? If yes, the database by using “DISABLE
How? TRIGGER triggerName ON<> We also
have an option to disable all the
trigger by using, “DISABLE Trigger ALL
ON ALL SERVER”
Question 47

What is a Live A live lock is one where a request for


Lock? an exclusive lock is repeatedly denied
because a series of overlapping
shared locks keep interferring. A live
lock also occurs when read
transactions create a table or page.
Question 48

How to fetch Records can be fetched for both Odd


alternate records and Even row numbers- To display
from a table? even numbers-. Select employeeId
? from (Select rowno, employeeId from
employee) where mod(rowno,2)=0 To
display odd numbers-. Select
employeeId from (Select rowno,
employeeId from employee) where
mod(rowno,2)=1
Question 49
When a COMMIT is uded in a
Define COMMIT and transaction all chnages made in the
give an example? transaction are written into the
database permanently. Example:
BEGIN TRANSACTION; DELETE FROM
HR.JobCandidate WHERE
JobCandidateID = 20; COMMIT
TRANSACTION; The above example
deletes a job candidate in a SQL
server.
Question 50

Can you join table A table can be joined to itself using


by itself? self join, when you want to create a
result set that joins records in a table
with other records in the same table.
Question 51
When two or more tables has been
Explain Equi join joined using equal to operator then
with example this category is called as equi join. Just
we need to concentrate on condition
is equal to(=) between the columns in
the table. Example: Select
a.Employee_name,b.Department_na
me from Employee a,Employee b
where
a.Department_ID=b.Department_ID
Question 52
The SELECT DISTINCT is used to get
How do we avoid distinct data from tables using a
getting duplicate query. The below SQL query selects
entries in a query? only the DISTINCT values from the
“Country” column in the “Customers”
table: SELECT DISTINCT Country
FROM Customers;
Question 53
Lets take an example: Select * into
How can you studentcopy from student where 1=2
create an empty Here, we are copying student table to
table from an another table with the same
existing table? structure with no rows copied.
Question 54
SELECT * FROM (SELECT *,
Write a Query to ROW_NUMBER() OVER (ORDER BY
display odd records student_no) AS RowID FROM student)
from student WHERE row_id %2!=0
table?
Question 55
When two or more tables are joining
Explain Non Equi without equal to condition then that
Join with example? join is known as Non Equi Join. Any
operator can be used here that is
<>,!=,<,>,Between. Example: Select
b.Department_ID,b.Department_nam
e from Employee a,Department b
where a.Department_id <>
b.Department_ID;
Question 56
By using the SET ROWCOUNT
How can you delete command. It limits the number of
duplicate records in records affected by a command. Let’s
a table with no take an example, if you have 2
primary key? duplicate rows, you would SET
ROWCOUNT 1, execute DELETE
command and then SET ROWCOUNT
0
Question 57 Both the NVL(exp1, exp2) and
NVL2(exp1, exp2, exp3) functions
Difference check the value exp1 to see if it is null.
between NVL and With the NVL(exp1, exp2) function, if
NVL2 functions? exp1 is not null, then the value of
exp1 is returned; otherwise, the value
of exp2 is returned, but case to the
same data type as that of exp1. With
the NVL2(exp1, exp2, exp3) function,
if exp1 is not null, then exp2 is
returned; otherwise, the value of
exp3 is returned.
Question 59 1. Clustered indexes can be read
rapidly rather than non-clustered
What is the indexes.
difference between 2. Clustered indexes store data
clustered and non- physically in the table or view
clustered indexes? whereas, non-clustered indexes do
not store data in the table as it has
separate structure from the data row.
Question 60

What does this The given syntax indicates that the


query says? user can grant access to another user
GRANT too.
privilege_name ON
object_name TO
{user_name|PUBLIC
|role_name} [WITH
GRANT OPTION];
Question 61

Where MyISAM Each MyISAM table is stored on disk


table is stored? in three files.
1. The “.frm” file stores the table
definition.
2. The data file has a ‘.MYD’ (MYData)
extension.
3. The index file has a ‘.MYI’ (MYIndex)
extension.
Question 62

What does It compresses the MyISAM tables,


myisamchk do? which reduces their disk or memory
usage.
Question 63

What is ISAM? IISAM is abbreviated as Indexed


Sequential Access Method. It was
developed by IBM to store and
retrieve data on secondary storage
systems like tapes.
Question 64

What is Database IWhite box testing includes: Database


White box testing? Consistency and ACID properties
Database triggers and logical views
Decision Coverage, Condition
Coverage, and Statement Coverage
Database Tables, Data Model, and
Database Schema Referential
integrity rules.
There are 3 different types of SQL
Question 65 sandbox:
1. Safe Access Sandbox: Here a user
What are the can perform SQL operations such as
different types of creating stored procedures, triggers
SQL sandbox? etc. but cannot have access to the
memory as well as cannot create files.
2. External Access Sandbox: Users can
access files without having the right to
manipulate the memory allocation.
3. Unsafe Access Sandbox: This
contains untrusted codes where a user
can have access to memory.
Question 66

What is Database This testing involves 1. Data Mapping


Black Box Testing? 2. Data stored and retrieved 3. Use of
Black Box testing techniques such as
Equivalence Partitioning and
Boundary Value Analysis (BVA).
Question 67

Explain Right This join is usable, when user wants


Outer Join with all the records from Right table
Example? (Second table) and only equal or
matching records from First or left
table. The unmatched records are
considered as null records. Example:
Select t1.col1,t2.col2….t ‘n’col ‘n.’. from
table1 t1,table2 t2 where
t1.col(+)=t2.col;
Question 68

What is a A SubQuery is a SQL query nested


Subquery? into a larger query. Example: SELECT
employeeID, firstName, lastName
FROM employees WHERE
departmentID IN (SELECT
departmentID FROM departments
WHERE locationID = 2000) ORDER BY
firstName, lastName;
Question 69

What is a A SubQuery is a SQL query nested


Subquery? into a larger query. Example: SELECT
employeeID, firstName, lastName
FROM employees WHERE
departmentID IN (SELECT
departmentID FROM departments
WHERE locationID = 2000) ORDER BY
firstName, lastName;
Question 70 The Intersect operator helps combine
two select statements and returns
What is the use of only those records that are common
the Intersect to both the select statements. So,
operator? after we get Table A and Table B over
here and if we apply the Intersect
operator on these two tables, then
we will get only those records that are
common to the result of the select
statements of these two.
Question 71

What is Cursor? A database Cursor is a control that


How to use a allows you to navigate around the
Cursor? table’s rows or documents.
Question 72

What is the The Union operator is used to


difference between combine the result set of two or
Union and Union All more select statements.
operators?
Question 73

What do you Self Join in SQL is used for joining a


understand by Self table with itself. Here, depending
Join? upon some conditions, each row of
the table is joined with itself and with
other rows of the table.
Question 74

What do you know Self Join in SL is used for joining a


about the stuff() table with itself. Here, depending
function? upon some conditions, each row of
the table is joined with itself and with
other rows of the table.
Question 75

What is the ACID The full form of ACID is Atomicity,


property in a Consistency, Isolation, and Durability.
database? To check the reliability of the
transactions, ACID properties are
used.
Question 76 Entities: Entity can be a person, place,
thing, or any identifiable object for
What are Entities
which data can be stored in a
and Relationships?
database.
Relationships: Relationships between
entities can be referred to as the
connection between two tables or
entities.
Question 77
A foreign key is an attribute or a set of
What is a foreign
attributes that references to the
key?
primary key of some other table.
Basically, it is used to link together
two tables
Question 78
Datawarehouse refers to a central
What is a
repository of data where the data is
Datawarehouse?
assembled from multiple sources of
information. Those data are
consolidated, transformed and made
available for the mining as well as
online processing. Warehouse data
also have a subset of data called Data
Marts
Question 79
Collation is defined as a set of rules
What do you mean
that determine how data can be
by Collation?
sorted as well as compared.
Character data is sorted using the
rules that define the correct character
sequence along with options for
specifying case-sensitivity, character
width etc.
Question 80
A Stored Procedure is a function
What is a Stored
which consists of many SQL
Procedure?
statements to access the database
system. Several SQL statements are
consolidated into a stored procedure
and execute them whenever and
wherever required which saves time
and avoid writing code again and
again.
Question 81
There are a lot of ways to fetch
How can you fetch
characters from a string. For
first 5 characters
of the string? example:
Select SUBSTRING(StudentName,1,5)
as studentname from student
Question 82
Data Integrity defines the accuracy as
What do you mean
well as the consistency of the data
by data integrity?
stored in a database. It also defines
integrity constraints to enforce
business rules on the data when it is
entered into an application or a
database.
Question 83
If a table is dropped, all things
What is the
associated with the tables are
difference between
DROP and dropped as well. This includes - the
TRUNCATE relationships defined on the table
statements? with other tables, the integrity checks
and constraints, access privileges and
other grants that the table has.
IDenormalization is the inverse
Question 84 process of normalization, where the
What is normalized schema is converted into
Denormalization? a schema which has redundant
information. The performance is
improved by using redundancy and
keeping the redundant data
consistent. The reason for
performing denormalization is the
overheads produced in query
processor by an over-normalized
structure.

You might also like