0% found this document useful (0 votes)
12 views4 pages

Interview Questions

The document provides a comprehensive overview of SQL concepts, including stored procedures, views, indexes, and various SQL functions. It covers key topics such as primary and foreign keys, different types of joins, normalization techniques, and the differences between DELETE and TRUNCATE commands. Additionally, it includes example queries and explanations for operations like retrieving the highest salary and deleting duplicate rows.

Uploaded by

Venkatesh Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Interview Questions

The document provides a comprehensive overview of SQL concepts, including stored procedures, views, indexes, and various SQL functions. It covers key topics such as primary and foreign keys, different types of joins, normalization techniques, and the differences between DELETE and TRUNCATE commands. Additionally, it includes example queries and explanations for operations like retrieving the highest salary and deleting duplicate rows.

Uploaded by

Venkatesh Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL Questions,

1. What is procedures.
A stored procedure in MS SQL Server is a precompiled set of SQL statements stored in the database.
It can be reused and executed multiple times, often with different parameters, to perform specific
database operations such as data retrieval, updates, or business logic execution.

2. Write a query to retrieve the highest salary in table.

Select salary from (


Select salary, Row_Number() over (order by salary desc ) as rownumber ) from salary_table)as salary
Where rownumber =1

3. What is views and what are those types.

View is virtual table we can join and simply multiple tables into single virtual table. Views can be
used to restrict access to sensitive data by providing control access to specific columns and rows.
It won’t store any data, and it will store query only.
 Simple View
 Complex View
 Materialized view.

4. What is pat index and syntax.


Patindex function is used to find the starting position of a pattern within a string. It similar to
charindex but supports wild card entries like operator.

Pateindex(‘%e%’, String value)

5. Define Row_number ()
Function assigns a unique number to each row in the result set based on the specified order. It does
not handle ties well as which row gets a unique number.

6. What is trigger and how you used triggers.

Triggers are mainly used for inserting, deleting, and updating things happened on top of table it will
insert one new record the audit table. Whenever you can see what will happened in the audit table.

7. Explain about Functions and stored procedures.


 The function must return to value but in stored procedures not required.
 We can use transactions in procedures whereas in functions we can’t use.
 Inline functions can be through view that takes a parameter and can be used in joins and other
row set operations.
 Function can be called from procedure but procedures cannot be called from function.

8. What is index.
Index is retrieve the data Fastly and it act like a search performance, Whenever you are creating
primary key it will create automatically index as well. Creating index it will generate the B-Tree
structure like node, root, intermediate.
9. What is Charindex function?
It returns the position of the number of the first occurrence with in the string. Which position it will
shows.

Charindex(‘String word ’,string )

10. Replace function

The REPLACE function in MS SQL Server is used to replace all occurrences of a specified substring
within a string with another substring.

11. How you will delete duplicate rows in a table.

; with CTE
As
(
Select employee_code, date, row_number() over (partitions by employee_code, date order by
employee_code) as rownumber from tablename
)
Select * from CTE where rownmber >1

12. What is primary key

The primary key is a constraint in SQL that uniquely identifies each record in a table. It ensures that
the column(s) designated as the primary key has unique values and cannot contain NULL values.
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName NVARCHAR(50),
LastName NVARCHAR(50)
)
13. What is Foreign key

A foreign key is a constraint in SQL that establishes a relationship between two tables. It ensures that
the value in a column (or combination of columns) matches the value in a column of another table,
referred to as the parent table.
The foreign key is used to enforce referential integrity, ensuring that the data in the child table
corresponds to valid data in the parent table.

14. What are the constraints.


 Primary key constraint
 Foreign key constraint
 Unique key
 Not Null
 Default

15. How many types Joins and what are those.


1. Inner Join,
2. Left join,
3. Right join
4. Full join
5. Cross join.
16. What is Temp Tables
It will load the data into tempdb and perform the operation
It will directly pull data from tempdb, and work fast when comparing with table variables when we
deals with Large data.

17. Unique key constraint.

A unique key constraint is used to ensure that all the values in a column or a combination of
columns are distinct. It enforces uniqueness in a table, allowing only one occurrence of each
value, except for NULL values (which are allowed once).

18. Table variables.

A table variable in SQL Server is a type of variable that stores data in a tabular format, similar to a
temporary table. It is defined using the DECLARE statement and is used to store intermediate results
in memory during query execution.

19. What is inner join


Merging two are more tables using key column is inner join.

Select * from table1 join table2 on t1.empcode=t2.empcode

20. Types of commands


 DDL
 DML
 DQL
 DCL
 TCL

21. Difference between delete and truncate.


The DELETE statement removes rows from a table, one at a time. It allows filtering rows using a
WHERE clause.

DELETE FROM table_name WHERE condition;

The TRUNCATE statement removes all rows from a table by deallocating the data pages used to
store the table data. It does not allow filtering.

TRUNCATE TABLE table_name

22. Drop what it perform the operation.

It will drop the whole table and it will delete logs as well.

23. What are system functions in SQL Server?

Examples: GETDATE(), ISNULL(), LEN(), SUBSTRING().

24. What Union and union all

Union: it will sort the data and group the data and it will give only matched records.

Union All: it won’t perform any operation. It will combine the data from the table and give as output.

25. What identity property.


We create an identity column to auto generate incremental values. It generates values based on
predefined seed value and incremental value.

DBCC check ident (tablesname, reseed, reseed number)

26. What is Subquery & correleated subquery.

It will excute inner query first and output of inner query is the input of the outer query

It will excute outside query and output of outer query will be input of the inner query.

27. 3rd highest salary

Select salary from (

Select salary ,row_number() over (order by salary desc) as renumber from salarytable) as salary

Where renumber =3

28. What are those techniques in normalization.

Normalization is a database technique to remove the redundancy data or to avoid the redundant data

There 6 normalizations are the 1NF to 6 NF.

29. Why we use Group By clause

GROUP BY clause is used to group rows that have the same values in specified columns into summary rows, like
finding the sum, average, count, etc., for each group. The GROUP BY clause is typically used with aggregate
functions such as COUNT(), SUM(), AVG(), MIN(), or MAX().

30. IF condition ()

If the condition Is excutes and it’s true, then the statement will excute. If the condition is false it will go through
else condition and it will excute that condition..

You might also like