SQL Interview Questions for Freshers
SQL Interview Questions for Freshers
1. What is DBMS?
A Database Management System (DBMS) is a program that controls creation,
maintenance and use of a database. DBMS can be termed as File Manager that
manages data in a database rather than saving it in file systems.
2. What is RDBMS?
RDBMS stands for Relational Database Management System. RDBMS store the data
into the collection of tables, which is related by common fields between the columns
of the table. It also provides relational operators to manipulate the data stored into
the tables.
3. What is SQL?
SQL stands for Structured Query Language , and it is used to communicate with the
Database. This is a standard language used to perform tasks such as retrieval,
updation, insertion and deletion of data from a database.
Standard SQL Commands are Select.
4. What is a Database?
Database is nothing but an organized form of data for easy access, storing, retrieval
and managing of data. This is also known as structured form of data which can be
accessed in many ways.
Example:.
Table: Employee.
A Primary key constraint has automatic unique constraint defined on it. But not, in the
case of Unique Key.
There can be many unique constraint defined per table, but only one Primary key
constraint defined per table.
9. What is a join?
This is a keyword used to query data from more tables based on the relationship
between the fields of the tables. Keys play a major role when JOINs are used.
Inner Join.
Inner join return rows when there is at least one match of rows between the tables.
Right Join.
Right join return rows which are common between the tables and all rows of Right
hand side table. Simply, it returns all the rows from the right hand side table even
though there are no matches in the left hand side table.
Left Join.
Left join return rows which are common between the tables and all rows of Left hand
side table. Simply, it returns all the rows from Left hand side table even though there
are no matches in the Right hand side table.
Full Join.
Full join return rows when there are matching rows in any one of the tables. This
means, it returns all the rows from the left hand side table and all the rows from the
right hand side table.
Database Normal
Forms
This should remove all the duplicate columns from the table. Creation of tables for the
related data and identification of unique columns.
Meeting all requirements of the first normal form. Placing the subsets of data in
separate tables and Creation of relationships between the tables using primary keys.
This should meet all requirements of 2NF. Removing the columns which are not
dependent on primary key constraints.
6th Normal Form is not standardized, yet however, it is being discussed by database
experts for some time. Hopefully, we would have a clear & standardized definition for
6th Normal Form in the near future…
A view is a virtual table which consists of a subset of data contained in a table. Views
are not virtually present, and it takes less space to store. View can have data of one or
more tables combined, and it is depending on the relationship.
Unique Index.
This indexing does not allow the field to have duplicate values if the column is unique
indexed. Unique index can be applied automatically when primary key is defined.
Clustered Index.
This type of index reorders the physical order of the table and search based on the key
values. Each table can have only one clustered index.
NonClustered Index.
NonClustered Index does not alter the physical order of the table and maintains
logical order of data. Each table can have 999 nonclustered indexes.
Self-Referencing Relationship.
A common customer complaint at the MyFlix Video Library is the low number of movie
titles. The management wants to buy movies for a category which has least number of
titles.
A correlated subquery cannot be considered as independent query, but it can refer the
column in a table listed in the FROM the list of the main query.
A Non-Correlated sub query can be considered as independent query and the output
of subquery are substituted in the main query.
Example: When a new student is added to the student database, new records should
be created in the related tables like Exam, Score and Attendance tables.
TRUNCATE removes all rows from the table. Truncate operation cannot be rolled back.
25. What are local and global variables and their differences?
Local variables are the variables which can be used or exist inside the function. They
are not known to the other functions and those variables cannot be referred or used.
Variables can be created whenever that function is called.
Global variables are the variables which can be used or exist throughout the program.
Same variable declared in global cannot be used in functions. Global variables cannot
be created whenever that function is called.
NOT NULL.
CHECK.
DEFAULT.
UNIQUE.
PRIMARY KEY.
FOREIGN KEY.
A nonclustered index does not alter the way it was stored but creates a complete
separate object within the table. It point back to the original table rows after
searching.
Scalar Functions.
Scalar returns unit, variant defined the return clause. Other two types return table as a
return.
Accent Sensitivity.
Kana Sensitivity – Japanese Kana characters.
Disadvantage is that it can be executed only in the Database and utilizes more
memory in the database server.
MINUS operator is used to return rows from the first query but not from the second
query. Matching records of first and second query and other rows from the first query
will be displayed as a result set.
Example-.
Select st.StudentID, Ex.Result from student st, Exam as Ex where st.studentID = Ex.
StudentID
Here, st refers to alias name for student table and Ex refers to alias name for exam
table.
Example -.
Example -.
Select * from Student where studentname like 'a%'
Select * from Student where studentname like 'ami_'
o Data definition language (DDL): It defines the data structure that consists of
commands like CREATE, ALTER, DROP, etc.
o Data control language (DCL): It controls access to the data stored in the
database. The commands in this category include GRANT and REVOKE.
o Logical operators: These operators evaluate the expressions and return their
results in True or False. This operator includes ALL, AND, ANY, ISNULL, EXISTS,
BETWEEN, IN, LIKE, NOT, OR, UNIQUE.
30) What are the differences between SQL, MySQL, and SQL Server?
The following comparison chart explains their main differences:
SQL first appeared in MySQL first appeared on SQL Server first appeared
1974. May 23, 1995. on April 24, 1989.
SQL has no variables. MySQL can use variables SQL Server can use
constraints and data types. variables constraints and
data types.
60) What is the difference between the WHERE and HAVING clauses?
The main difference is that the WHERE clause is used to filter records before any
groupings are established, whereas the HAVING clause is used to filter values from a
group. The below comparison chart explains the most common differences:
WHERE HAVING
It does not allow to work with aggregate It can work with aggregate
functions. functions.
This clause can be used with the SELECT, This clause can only be used with
UPDATE, and DELETE statements. the SELECT statement.
SQL provides seven (7) aggregate functions, which are given below:
o AVG(): This function is used to returns the average value from specified columns.
o COUNT(): This function is used to returns the number of table rows, including rows
with null values.
o MAX(): This function is used to returns the largest value among the group.
o MIN(): This function is used to returns the smallest value among the group.
o SUM(): This function is used to returns the total summed values(non-null) of the
specified column.
o Examine the database to extract information regarding the version and structure
of the database.