Find Interview Questions for Top Companies
Ques:- Write a SQL Stored Procedure to create a GUID and add it to a table. Make that GUID an OUTPUT of that Procedure
Right Answer:
```sql
CREATE PROCEDURE CreateGuidAndInsert
@NewGuid UNIQUEIDENTIFIER OUTPUT
AS
BEGIN
-- Generate a new GUID
SET @NewGuid = NEWID();

-- Insert the GUID into the table (replace 'YourTable' with your actual table name)
INSERT INTO YourTable (GuidColumn) VALUES (@NewGuid);
END
```
Ques:- What is Views in sql server?
Right Answer:
A view in SQL Server is a virtual table that is based on the result of a SQL query. It can contain rows and columns from one or more tables and is used to simplify complex queries, enhance security by restricting access to specific data, and present data in a specific format.
Ques:- What is joins?What is the use?Where it is use?
Right Answer:
A join is a SQL operation that combines rows from two or more tables based on a related column between them. Joins are used to retrieve data that is spread across multiple tables, allowing for more complex queries and data analysis. They are commonly used in database queries to gather related information, such as combining customer and order data.
Ques:- What's the use of SQL Profiler?
Right Answer:
SQL Profiler is a tool used to monitor and analyze SQL Server events, allowing users to capture and replay SQL queries, track performance issues, and troubleshoot database problems.
Ques:- What is the difference between Varchar and Varchar2?
Right Answer:
Varchar can store variable-length strings up to 8,000 bytes, while Varchar2 can store variable-length strings up to 4,000 bytes (or up to 32,767 bytes in some configurations) and is more efficient in terms of storage and performance.
Ques:- How do you optimize stored procedures ?
Right Answer:
To optimize stored procedures, you can:

1. **Use Proper Indexing**: Ensure that the tables involved have appropriate indexes to speed up data retrieval.
2. **Avoid Cursors**: Replace cursors with set-based operations whenever possible.
3. **Minimize Data Retrieval**: Select only the necessary columns and rows to reduce the amount of data processed.
4. **Use Temporary Tables**: Utilize temporary tables to store intermediate results if needed.
5. **Analyze Execution Plans**: Review execution plans to identify bottlenecks and optimize queries accordingly.
6. **Parameter Sniffing**: Use `OPTION (RECOMPILE)` for queries that perform poorly with parameter sniffing.
7. **Avoid Functions on Indexed Columns**: Avoid using functions on indexed columns in the WHERE clause, as it can prevent index usage.
8. **Batch Processing**: Break large operations into smaller batches to reduce locking and improve performance.
9. **Update Statistics**: Regularly update statistics to ensure
Ques:- How to remove duplicate records from a table?
Right Answer:
To remove duplicate records from a table in SQL Server, you can use a Common Table Expression (CTE) with the `ROW_NUMBER()` function. Here’s an example query:

```sql
WITH CTE AS (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY column1, column2 ORDER BY (SELECT NULL)) AS rn
FROM your_table
)
DELETE FROM CTE WHERE rn > 1;
```

Replace `column1`, `column2` with the columns that define duplicates, and `your_table` with the name of your table.
Ques:- What is the difference between the full, simple and bulk log recovery models?
Right Answer:
The full recovery model allows for complete data recovery by maintaining a full transaction log, enabling point-in-time recovery. The simple recovery model does not keep a transaction log, which means that after a transaction is committed, it cannot be recovered; it is suitable for scenarios where data loss is acceptable. The bulk-logged recovery model allows for bulk operations to be minimally logged, reducing log space usage while still allowing for point-in-time recovery, but it does not guarantee it during bulk operations.
Ques:- What is different between int and bint?
Right Answer:
In SQL Server, `int` is a data type that stores integer values ranging from -2,147,483,648 to 2,147,483,647, while `bigint` (often abbreviated as `bint`) is a data type that stores larger integer values ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
Ques:- Can we generate a trigger for two tables? if so what is the query to generate a trigger for two tables employye table and department table with employee having department no.
Right Answer:
No, a single trigger cannot be directly created for two tables in SQL Server. However, you can create separate triggers for each table. Here’s an example of how to create triggers for the `employee` and `department` tables:

```sql
CREATE TRIGGER trg_employee
ON employee
AFTER INSERT, UPDATE
AS
BEGIN
-- Trigger logic for employee table
END;

CREATE TRIGGER trg_department
ON department
AFTER INSERT, UPDATE
AS
BEGIN
-- Trigger logic for department table
END;
```
Ques:- How functional dependency is related to database table design?
Right Answer:
Functional dependency is a relationship between attributes in a database table where one attribute uniquely determines another. It is crucial for database table design as it helps in organizing data efficiently, ensuring data integrity, and minimizing redundancy by guiding the normalization process.
Ques:- What is SQL*Loader?Difference between
Right Answer:
SQL*Loader is a utility provided by Oracle for loading data from external files into Oracle database tables. It allows for high-speed data loading and supports various data formats.

The difference between SQL*Loader and other data loading methods (like INSERT statements or external tables) is that SQL*Loader is specifically designed for bulk data loading, offering features like data transformation, error handling, and the ability to load data from multiple files efficiently.
Ques:- What is a dirty page and dirty report?
Right Answer:
A dirty page is a page in memory that has been modified but not yet written to disk. A dirty report is a mechanism that identifies these dirty pages, indicating which pages need to be flushed to disk to ensure data consistency and durability.
Ques:- What is merging?
Right Answer:
Merging is the process of combining data from two or more sources into a single dataset, often used to consolidate records or integrate changes in data. In SQL Server, this can be done using the MERGE statement, which allows you to insert, update, or delete records in a target table based on matching conditions with a source table.
Ques:- What is the pivot operator in MS SQL Server2005? What is the use of it and how do we use it
Right Answer:
The PIVOT operator in MS SQL Server 2005 is used to transform rows into columns, allowing for easier data analysis and reporting. It is typically used to aggregate data and present it in a more readable format.

To use the PIVOT operator, you follow this syntax:

```sql
SELECT <non-pivoted column>, [column1], [column2], ...
FROM
(
SELECT <non-pivoted column>, <pivoted column>, <aggregate function>
FROM <table>
) AS SourceTable
PIVOT
(
<aggregate function>(<pivoted column>)
FOR <pivoted column> IN ([column1], [column2], ...)
) AS PivotTable;
```

Replace `<non-pivoted column>`, `<pivoted column>`, `<aggregate function>`, and `<table>` with your specific data and requirements.
Ques:- How many types of system privileges are there, Can we add or delete privileges?
Right Answer:
There are two types of system privileges: administrative privileges and object privileges. In SQL Server, you cannot directly add or delete system privileges; they are predefined by the system. However, you can grant or revoke them to users or roles.
Ques:- What are DTS subroutines? What is their use and How do you write them?
Right Answer:
DTS (Data Transformation Services) subroutines are reusable blocks of code that can be called from within a DTS package to perform specific tasks or operations. They are used to encapsulate logic that can be reused across multiple packages, improving maintainability and reducing redundancy.

To write a DTS subroutine, you typically use VBScript or JScript. You define the subroutine in the "Global Variables" section of the DTS package, and it can be called from tasks or other subroutines within the package. Here's a simple example in VBScript:

```vbscript
Function MySubroutine()
' Your code here
MsgBox "Hello from MySubroutine!"
End Function
```

You can call this subroutine from a task by using the following syntax:

```vbscript
Call MySubroutine()
```
Ques:- What is the Disadvantage of StoredProcedure?
Right Answer:
The disadvantages of stored procedures include:

1. **Complexity**: They can become complex and difficult to maintain as business logic grows.
2. **Portability**: Stored procedures are often database-specific, making it harder to switch database systems.
3. **Debugging**: Debugging stored procedures can be more challenging compared to application code.
4. **Version Control**: Managing versions of stored procedures can be cumbersome.
5. **Performance**: Poorly written stored procedures can lead to performance issues.
6. **Security**: They can introduce security risks if not properly managed, such as SQL injection vulnerabilities.


SQL, or Structured Query Language, is the essential tool for anyone working with relational databases. It serves as the universal language for interacting with these databases, allowing users to organize, retrieve, and manage vast amounts of data effectively. Developed in the 1970s, SQL has become the standardized method for database communication across a wide range of applications, from small business systems to enterprise-level data warehouses.

The power of SQL lies in its declarative nature. Instead of telling the computer how to find data, you simply tell it what data you want. This is done through a concise set of commands, such as SELECT to retrieve data, INSERT to add new records, UPDATE to modify existing records, and DELETE to remove them. These commands, often combined with clauses like WHERE to filter data and JOIN to link tables, enable complex data operations with relatively simple statements. For example, a single query can retrieve a list of all customers from a specific city, calculate their total spending, and sort the results by name.

SQL is a foundational technology for data science, business intelligence, and web development. It is used to query databases that power everything from social media platforms to banking systems. Its reliability, efficiency, and widespread adoption make it an indispensable skill for database administrators, developers, and data analysts. Mastering SQL provides the ability to unlock insights from data, maintain data integrity, and build robust, data-driven applications.

AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users