Interview Questions
Interview 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.
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.
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.
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.
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.
The REPLACE function in MS SQL Server is used to replace all occurrences of a specified substring
within a string with another substring.
; 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
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.
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).
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.
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.
It will drop the whole table and it will delete logs as well.
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.
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.
Select salary ,row_number() over (order by salary desc) as renumber from salarytable) as salary
Where renumber =3
Normalization is a database technique to remove the redundancy data or to avoid the redundant data
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..