Top 250 SQL Interview Questions and Answers

Updated 13 Feb 2025

Q101. 1) Write a query of Sub Query .....

Ans.

A subquery is a query nested inside another query. It is used to retrieve data from multiple tables or perform complex calculations.

  • A subquery is enclosed within parentheses and is usually placed within the WHERE or HAVING clause of the outer query.

  • The result of the subquery is used by the outer query to filter or manipulate the data.

  • Subqueries can be used to retrieve data from multiple tables, perform calculations, or compare values.

  • Examples of subqueries include finding the...read more

View 1 answer

Q102. Explain operator in sql

Ans.

Operators in SQL are symbols used to perform operations on data, such as arithmetic, comparison, and logical operations.

  • Operators in SQL include arithmetic operators (+, -, *, /), comparison operators (=, <>, >, <, >=, <=), logical operators (AND, OR, NOT), and more.

  • Arithmetic operators are used to perform mathematical calculations on data, such as adding two numbers together.

  • Comparison operators are used to compare values in a query, such as checking if one value is equal to...read more

Add your answer

Q103. What is acid property in sql

Ans.

ACID properties in SQL refer to a set of properties that ensure database transactions are processed reliably.

  • ACID stands for Atomicity, Consistency, Isolation, and Durability

  • Atomicity ensures that either all operations in a transaction are completed successfully or none are

  • Consistency ensures that the database remains in a consistent state before and after the transaction

  • Isolation ensures that multiple transactions can be executed concurrently without affecting each other

  • Dura...read more

Add your answer
Frequently asked in

Q104. What is difference between first projection and third projection?

Ans.

First projection is a front view of an object, while third projection is a side view.

  • First projection shows the front view of an object, while third projection shows the side view.

  • First projection is typically labeled as 'F' on engineering drawings, while third projection is labeled as 'T'.

  • First projection is used to show the overall shape and size of an object, while third projection is used to show the depth and height.

View 1 answer
Are these interview questions helpful?

Q105. what is sql,what is join operation

Ans.

SQL is a programming language used for managing and manipulating relational databases. Join operation combines rows from two or more tables based on a related column.

  • SQL is a language used to interact with databases

  • It allows users to create, modify, and retrieve data from databases

  • Join operation combines data from multiple tables based on a common column

  • Types of joins include inner join, left join, right join, and full outer join

  • Example: SELECT * FROM table1 JOIN table2 ON ta...read more

Add your answer
Frequently asked in

Q106. What are the Recovery models

Ans.

Recovery models determine how SQL Server manages transaction log files and provides options for data recovery.

  • Full recovery model: Allows for complete data recovery by storing all transactions in the transaction log.

  • Simple recovery model: Automatically reclaims log space to keep the log file small, but limits recovery options.

  • Bulk-logged recovery model: Minimally logs bulk operations, reducing log space usage but increasing potential for data loss.

  • Examples: Full recovery mode...read more

View 1 answer
Share interview questions and help millions of jobseekers 🌟

Q107. If we truncate a table, the new row will start from 1 or continue?

Ans.

The new row will start from 1 after truncating a table.

  • Truncating a table removes all rows from the table, resetting the row count to 1.

  • The next row inserted after truncation will have an ID of 1.

  • Truncating a table does not reset the auto-increment value of the primary key column.

Add your answer

Q108. Difference between DELETE and TRUNCATE statement &amp; DROP and TRUNCATE?

Ans.

DELETE removes specific rows while TRUNCATE removes all rows. DROP deletes the entire table while TRUNCATE only removes data.

  • DELETE is a DML command while TRUNCATE is a DDL command.

  • DELETE can be rolled back while TRUNCATE cannot be rolled back.

  • DELETE is slower than TRUNCATE.

  • DROP deletes the entire table and its structure while TRUNCATE only removes data.

  • TRUNCATE resets the identity of the table while DELETE does not.

  • Examples: DELETE FROM table_name WHERE condition; TRUNCATE T...read more

Add your answer

SQL Jobs

Power Bi+ SQL - Noida - Immediate joiner - 5+ yrs. Exp To apply 4-9 years
Ienergizer
4.6
₹ 5 L/yr - ₹ 9 L/yr
Noida
Java Developer (Database) 5-8 years
A.P. Moller Maersk
4.2
₹ 20 L/yr - ₹ 28 L/yr
Bangalore / Bengaluru
Database Engineer : Oracle DBA 6-8 years
Apple India Pvt Ltd
4.3
Hyderabad / Secunderabad

Q109. use dense rank function

Ans.

Dense rank function assigns a rank to each row within a partition of a result set, with no gaps in the ranking values.

  • Use the DENSE_RANK() function in SQL to assign a unique rank to each row within a partition

  • It is similar to the RANK() function but does not leave gaps in the ranking values

  • Example: SELECT column1, DENSE_RANK() OVER (PARTITION BY column2 ORDER BY column3) AS dense_rank FROM table_name

Add your answer

Q110. What is DQL and what are the functionalities provide by DQL?

Ans.

DQL stands for Document Query Language. It is used to query documents in a document-oriented database like MongoDB.

  • DQL is used to retrieve documents from a MongoDB database.

  • It supports a wide range of query operators and expressions.

  • DQL can be used to perform complex queries on nested documents.

  • It also supports aggregation pipeline for advanced data processing.

  • Examples of DQL queries include find(), findOne(), and aggregate().

Add your answer

Q111. What is the joining data

Ans.

Joining data refers to the date on which an employee officially starts working at a new company or branch.

  • Joining data is the date when an employee's employment officially begins at a new company or branch.

  • It is important for HR and administrative purposes to track when employees start working.

  • For example, if an employee joins a company on January 15th, 2022, that would be their joining date.

Add your answer

Q112. What are the SQL DML commands

Ans.

SQL DML commands are used to manipulate data in a database.

  • DML stands for Data Manipulation Language

  • Common DML commands include INSERT, UPDATE, DELETE

  • INSERT is used to add new data to a table

  • UPDATE is used to modify existing data in a table

  • DELETE is used to remove data from a table

Add your answer

Q113. What is dynamic SQL and how do you execute it?

Ans.

Dynamic SQL is a technique to generate SQL statements at runtime based on user input or other conditions.

  • Dynamic SQL is used to create flexible and customizable queries.

  • It allows for the creation of complex queries with multiple conditions.

  • Dynamic SQL can be executed using prepared statements or by concatenating strings.

  • It is important to properly sanitize user input to prevent SQL injection attacks.

Add your answer

Q114. What is sql aggregation function

Ans.

SQL aggregation functions perform calculations on multiple rows of a single column of a table.

  • Aggregation functions include COUNT, SUM, AVG, MAX, and MIN.

  • They are used with the SELECT statement to retrieve data from a table.

  • Examples: SELECT COUNT(*) FROM customers; SELECT AVG(price) FROM products;

  • Aggregate functions can also be used with the GROUP BY clause to group data by one or more columns.

Add your answer

Q115. What are SQL comments

Ans.

SQL comments are used to add explanatory notes or remarks within SQL code.

  • SQL comments start with a double hyphen (--), or can be enclosed between /* and */

  • Comments are ignored by the SQL engine and are not executed as part of the code

  • Comments can be used to improve code readability and provide documentation

  • Comments can be used to disable or temporarily remove parts of the code for testing or debugging purposes

View 1 answer
Frequently asked in

Q116. Write SQL program to join tables with some conditions

Ans.

SQL program to join tables with conditions

  • Use JOIN keyword to combine tables

  • Specify conditions using ON keyword

  • Use WHERE keyword to add additional conditions

  • Example: SELECT * FROM table1 JOIN table2 ON table1.id = table2.id WHERE table1.column = 'value'

Add your answer

Q117. Which types of insert used by you ?

Ans.

I have used carbide inserts and ceramic inserts in my previous projects.

  • Carbide inserts are commonly used for machining steel and other metals.

  • Ceramic inserts are used for high-speed machining of cast iron and other hard materials.

  • I have also used diamond inserts for machining non-ferrous materials like aluminum.

  • The choice of insert depends on the material being machined and the desired surface finish.

Add your answer

Q118. What is security concept in SQL server?

Ans.

Security concept in SQL server involves controlling access to data and ensuring confidentiality, integrity, and availability.

  • Authentication and authorization

  • Encryption and decryption

  • Auditing and monitoring

  • Role-based security

  • Row-level security

  • Transparent Data Encryption (TDE)

  • Always Encrypted

  • Dynamic Data Masking

  • Firewall and IP restrictions

Add your answer

Q119. Find all the numbers that appear at least three times consecutively return the result table in any order

Ans.

Find numbers that appear at least three times consecutively in any order.

  • Use a window function to track consecutive numbers

  • Filter the result to only include numbers that appear at least three times consecutively

  • Return the result table in any order

Add your answer

Q120. What is magic table in SQLSERVER ?

Ans.

Magic table is a temporary table created by SQL Server during DML operations.

  • It is also known as inserted and deleted tables.

  • Inserted table contains the new rows being added to a table.

  • Deleted table contains the rows being deleted from a table.

  • It is used in triggers to access the data being modified.

  • It cannot be directly queried or modified by the user.

Add your answer

Q121. Do you have knowledge about Index architecture in SQL Server

Ans.

Yes, I have knowledge about Index architecture in SQL Server.

  • Indexes in SQL Server are used to improve the performance of queries by allowing faster data retrieval.

  • There are different types of indexes in SQL Server, such as clustered indexes, non-clustered indexes, and unique indexes.

  • Clustered indexes determine the physical order of data in a table, while non-clustered indexes have a separate structure.

  • Indexes can be created on one or multiple columns of a table.

  • Indexes can b...read more

View 1 answer

Q122. What if person mistakenly put F for male and M for female in sql how do you solve this

Ans.

To solve the issue of mistakenly assigned gender values in SQL, you can update the incorrect values using SQL queries.

  • Identify the incorrect gender values in the SQL table

  • Use UPDATE statement with appropriate conditions to correct the values

  • For example, if 'F' is mistakenly assigned for male, update it to 'M' using UPDATE statement

View 1 answer
Frequently asked in

Q123. 3) Write a code to create Models to connect to the Database

Ans.

Code to create Models for connecting to a Database

  • Define a class for each table in the database

  • Use ORM frameworks like Sequelize or Django ORM for easier database connectivity

  • Specify the table name, columns, and their data types in the model

  • Define relationships between models using foreign keys or associations

  • Implement CRUD operations in the models to interact with the database

View 1 answer

Q124. can you do coding in SQL

Ans.

Yes, I am proficient in coding in SQL.

  • I have experience writing complex SQL queries to extract and manipulate data.

  • I can create stored procedures, functions, and triggers in SQL.

  • I am familiar with optimizing SQL queries for performance.

  • I have worked with databases such as MySQL, Oracle, and SQL Server.

Add your answer
Frequently asked in

Q125. What is sql, data science

Ans.

SQL is a programming language used for managing and querying relational databases. Data science involves analyzing and interpreting complex data to make informed decisions.

  • SQL stands for Structured Query Language and is used to communicate with databases.

  • Data science involves collecting, analyzing, and interpreting large amounts of data to gain insights and make decisions.

  • SQL is commonly used for tasks such as retrieving data, updating records, and creating reports.

  • Data scien...read more

Add your answer

Q126. Do you work with SQL or other tools? How you utilize them?

Ans.

Yes, I work with SQL and other tools to analyze data and generate reports.

  • I use SQL to query databases and extract relevant information.

  • I also utilize tools like Microsoft Excel and Tableau for data visualization.

  • By combining SQL queries with Excel functions, I can create comprehensive reports for stakeholders.

Add your answer

Q127. Do you have knowledge of Cloud service, SQL etc?

Ans.

Yes, I have knowledge of Cloud services such as AWS, Azure, and Google Cloud, as well as SQL databases.

  • Familiar with Cloud services like AWS, Azure, and Google Cloud

  • Proficient in SQL databases

  • Experience in setting up and managing databases in the Cloud

Add your answer

Q128. Explain JDBC-SQL

Ans.

JDBC-SQL is a Java API for connecting and executing SQL queries on a database.

  • JDBC stands for Java Database Connectivity

  • It allows Java programs to interact with databases using SQL

  • JDBC provides classes and interfaces for connecting to a database, sending queries, and retrieving results

  • Example: Establishing a connection to a database, creating a statement, executing queries, and processing results

Add your answer
Frequently asked in

Q129. Have you done any SQL projects?

Ans.

Yes, I have worked on several SQL projects.

  • Developed a database for a retail company to manage inventory and sales data using SQL Server

  • Created complex queries to extract data from multiple tables for a financial services firm

  • Optimized database performance by indexing and partitioning tables for a healthcare organization

Add your answer
Frequently asked in

Q130. Do you know SQL , JAVASCRIPT?

Ans.

Yes, I have experience with SQL and JavaScript.

  • I have strong SQL skills, including writing complex queries and stored procedures.

  • I am proficient in JavaScript for front-end development and have experience with frameworks like React and Angular.

  • I have used SQL databases like MySQL and PostgreSQL, as well as NoSQL databases like MongoDB.

  • I have developed web applications that interact with databases using SQL and JavaScript.

Add your answer
Frequently asked in

Q131. Do you know SqL or C Sharp

Ans.

Yes, I know both SQL and C#.

  • I have experience in writing SQL queries for database management.

  • I have worked on C# projects for developing desktop and web applications.

  • I am familiar with object-oriented programming concepts and database design principles.

Add your answer

Q132. Like what is oops, sql

Ans.

OOPs stands for Object-Oriented Programming and SQL stands for Structured Query Language.

  • OOPs is a programming paradigm based on the concept of objects, which can contain data in the form of fields and code in the form of procedures.

  • SQL is a domain-specific language used in programming and designed for managing data held in a relational database management system (RDBMS).

Add your answer

Q133. What is abstraction, SQL query to select even number rows

Ans.

Abstraction is the concept of hiding complex implementation details and showing only the necessary features to the user.

  • Abstraction helps in reducing complexity and improving code readability.

  • In SQL, you can select even number rows using the MOD function.

  • Example: SELECT * FROM table_name WHERE MOD(row_number, 2) = 0;

Add your answer
Frequently asked in

Q134. describe about the wroking of power bi with sql ?

Ans.

Power BI can connect to SQL databases to import data, create visualizations, and generate reports.

  • Power BI can connect to SQL Server, Azure SQL Database, and other SQL-based data sources.

  • Users can import data from SQL databases into Power BI for analysis and visualization.

  • Queries can be written in Power BI to directly query SQL databases for real-time data updates.

  • Power BI can create interactive dashboards and reports based on SQL data.

  • Users can schedule data refreshes to kee...read more

Add your answer

Q135. Pull dataset from SQL to Power BI and perform the visualization

Ans.

Use Power BI to connect to SQL database, import dataset, and create visualizations

  • Connect Power BI to SQL database

  • Import dataset from SQL into Power BI

  • Create visualizations using the imported data

Add your answer

Q136. What are diff design patterns in sql

Ans.

Design patterns in SQL are reusable solutions to common problems encountered in database design and development.

  • Singleton Pattern: Ensures a class has only one instance and provides a global point of access to it.

  • Factory Pattern: Creates objects without specifying the exact class of object that will be created.

  • Repository Pattern: Separates the logic that retrieves data from a data source from the business logic that acts on the data.

  • Decorator Pattern: Allows behavior to be ad...read more

Add your answer

Q137. what is server , sql

Ans.

A server is a computer or software that provides functionality for other programs or devices. SQL is a programming language used for managing data in relational databases.

  • A server is a computer or software that provides services or resources to other computers or devices on a network.

  • SQL (Structured Query Language) is a programming language used for managing and manipulating data in relational databases.

  • Servers can host websites, store files, manage network resources, and mor...read more

Add your answer

Q138. What is substring in SQL?

Ans.

Substring in SQL is a function that extracts a portion of a string based on a specified starting position and length.

  • Substring function is used to extract a part of a string based on the starting position and length provided.

  • Syntax: SUBSTRING(string_expression, start, length)

  • Example: SELECT SUBSTRING('Hello World', 1, 5) will return 'Hello'

Add your answer
Frequently asked in

Q139. How do you handle SQL Exceptions.

Ans.

I handle SQL Exceptions by catching them in try-catch blocks and logging the error details.

  • Catch SQL Exceptions in try-catch blocks

  • Log the error details for troubleshooting

  • Handle exceptions gracefully to prevent application crashes

Add your answer
Frequently asked in

Q140. How to debug sql proc

Ans.

Debugging SQL procedures involves using print statements, logging, and step-by-step execution.

  • Use print statements to output variable values at different stages of the procedure.

  • Enable logging to track the flow of the procedure and identify any errors.

  • Execute the procedure step-by-step to pinpoint the exact location of the issue.

  • Use tools like SQL Server Management Studio to debug stored procedures.

  • Check for syntax errors and ensure proper error handling within the procedure.

Add your answer

Q141. How is SSIS related to SQL Server?

Ans.

SSIS is a tool provided by Microsoft for data integration and workflow applications.

  • SSIS (SQL Server Integration Services) is a component of SQL Server used for building data integration and workflow applications.

  • It allows users to create packages to extract, transform, and load data from various sources into SQL Server databases.

  • SSIS can be used for tasks such as data migration, data warehousing, and ETL (Extract, Transform, Load) processes.

  • It provides a graphical interface ...read more

Add your answer

Q142. How to source a SQL file into database from command prompt

Ans.

To source a SQL file into database from command prompt, use the 'mysql' command followed by the database name and file path.

  • Open command prompt

  • Navigate to the directory where the SQL file is located

  • Use the 'mysql' command followed by the database name and file path

  • Example: mysql -u username -p database_name < file_path.sql

Add your answer

Q143. Calculate second highest salary using SQL as well as pyspark.

Ans.

Calculate second highest salary using SQL and pyspark

  • Use SQL query with ORDER BY and LIMIT to get the second highest salary

  • In pyspark, use orderBy() and take() functions to achieve the same result

Add your answer
Frequently asked in

Q144. Write sql code using rank

Ans.

Using SQL rank function to assign ranks to rows based on specified criteria.

  • Use the RANK() function to assign ranks to rows based on specified criteria.

  • Specify the ORDER BY clause to determine the criteria for ranking.

  • Use the PARTITION BY clause to rank rows within groups.

  • Example: SELECT column1, column2, RANK() OVER (ORDER BY column3) AS rank_column FROM table_name;

Add your answer
Frequently asked in

Q145. what is commit in SQL

Ans.

A commit in SQL is a command that saves all the changes made in a transaction to the database.

  • A commit is used to make all the changes made in a transaction permanent.

  • Once a commit is issued, the changes cannot be rolled back.

  • It is important to use commit to ensure data integrity and consistency.

  • Example: COMMIT; - this command is used to commit the changes in a transaction.

Add your answer

Q146. What are the basic concepts of SQL?

Ans.

SQL is a programming language used for managing and manipulating relational databases.

  • SQL stands for Structured Query Language

  • Basic concepts include SELECT (retrieve data), INSERT (add data), UPDATE (modify data), DELETE (remove data)

  • SQL uses commands like SELECT, INSERT, UPDATE, DELETE, JOIN, WHERE, GROUP BY, ORDER BY, etc.

  • SQL is used to interact with databases like MySQL, PostgreSQL, Oracle, SQL Server, etc.

Add your answer

Q147. what is sql and explain primary key

Ans.

SQL is a programming language used for managing and manipulating databases. Primary key is a unique identifier for each record in a table.

  • SQL stands for Structured Query Language

  • It is used to communicate with databases to perform tasks like querying data, updating records, and creating tables

  • Primary key is a column or a set of columns that uniquely identifies each record in a table

  • It must contain unique values and cannot have NULL values

  • Example: In a table of employees, the p...read more

Add your answer

Q148. What are contract in sql

Ans.

Contracts in SQL are agreements between two or more parties defining the terms of a relationship or operation.

  • Contracts in SQL are used to enforce business rules and ensure data integrity.

  • They can include constraints, triggers, stored procedures, and other database objects.

  • Examples of contracts in SQL include foreign key constraints, check constraints, and unique constraints.

Add your answer

Q149. Find top 5 countries with highest population in Spark and SQL

Ans.

Use Spark and SQL to find the top 5 countries with the highest population.

  • Use Spark to load the data and perform data processing.

  • Use SQL queries to group by country and sum the population.

  • Order the results in descending order and limit to top 5.

  • Example: SELECT country, SUM(population) AS total_population FROM table_name GROUP BY country ORDER BY total_population DESC LIMIT 5

Add your answer
Frequently asked in

Q150. What is the aggregate function?

Ans.

Aggregate functions are functions in databases that perform a calculation on a set of values and return a single value.

  • Aggregate functions are used in SQL queries to perform calculations on groups of rows and return a single result.

  • Examples of aggregate functions include SUM, AVG, COUNT, MIN, and MAX.

  • These functions are commonly used with the GROUP BY clause to group rows based on a specified column.

Add your answer
Frequently asked in

Q151. What is distinct in SQL?

Ans.

DISTINCT is used in SQL to retrieve unique values from a column or set of columns.

  • DISTINCT eliminates duplicate rows from the result set

  • It is often used in SELECT statements to only return unique values

  • Example: SELECT DISTINCT column_name FROM table_name

Add your answer
Frequently asked in

Q152. 4. How to connect SQL server to databricks

Ans.

To connect SQL server to Databricks, use JDBC/ODBC drivers and configure the connection settings.

  • Install the appropriate JDBC/ODBC driver for SQL server

  • Configure the connection settings in Databricks

  • Use the JDBC/ODBC driver to establish the connection

Add your answer

Q153. Write code on How to insert a record and db and fetch it and do unit test around it.

Ans.

Code to insert and fetch a record in a database with unit tests

  • Use a database connection to insert a record into the database

  • Write a query to fetch the inserted record from the database

  • Create unit tests to verify the insertion and fetching functionality

Add your answer

Q154. How many types Sql authentication

Ans.

There are two types of SQL authentication: Windows authentication and SQL Server authentication.

  • Windows authentication uses the user's Windows login credentials to access the database.

  • SQL Server authentication requires a separate username and password to access the database.

  • SQL Server authentication is less secure than Windows authentication.

  • SQL Server authentication is commonly used for web applications.

  • Windows authentication is commonly used for desktop applications.

Add your answer
Frequently asked in

Q155. What is Rollup?

Ans.

Rollup is a data aggregation technique used in databases and data analysis to summarize and condense data.

  • Rollup is used to generate summary reports or aggregated data from detailed data.

  • It is commonly used in SQL queries to group data and calculate totals, averages, or other aggregate functions.

  • Rollup can be used to create hierarchical summaries, where data is grouped at different levels of granularity.

  • For example, in a sales database, rollup can be used to generate a report...read more

Add your answer

Q156. Do you have experience with SQL and concurrency

Ans.

Yes, I have experience with SQL and concurrency.

  • I have worked with SQL databases such as MySQL, PostgreSQL, and SQLite.

  • I am familiar with writing complex SQL queries to retrieve and manipulate data.

  • I have experience optimizing SQL queries for performance.

  • I have implemented concurrency control mechanisms like transactions and locking in SQL databases.

  • I have used tools like pgAdmin and MySQL Workbench for database management.

Add your answer

Q157. Find 2nd max by sql, do Fibonacci series

Ans.

SQL query to find 2nd max and Fibonacci series implementation

  • For finding 2nd max, use ORDER BY and LIMIT in SQL query

  • For Fibonacci series, use a loop or recursive function

  • Fibonacci series starts with 0, 1 and each subsequent number is the sum of the previous two

  • Example SQL query: SELECT MAX(column_name) FROM table_name WHERE column_name < (SELECT MAX(column_name) FROM table_name)

  • Example Fibonacci series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

Add your answer

Q158. What are the differences between temp tables and table variables

Ans.

Temp tables are physical tables stored in tempdb, while table variables are in-memory structures.

  • Temp tables are stored in tempdb database, while table variables are created in memory.

  • Temp tables can be indexed and have statistics, while table variables cannot.

  • Temp tables can be used across multiple sessions, while table variables are limited to the current session.

  • Temp tables support DDL operations like ALTER TABLE, while table variables do not.

  • Temp tables are generally pref...read more

Add your answer

Q159. Difference between sql and sql server?

Ans.

SQL is a language used to manage databases, while SQL Server is a Microsoft product that includes a database management system.

  • SQL is a language used to interact with databases, while SQL Server is a Microsoft product that includes a database management system.

  • SQL can be used with various database management systems like MySQL, Oracle, etc., while SQL Server is specific to Microsoft.

  • SQL is a standard language for querying and managing databases, while SQL Server provides addi...read more

Add your answer
Frequently asked in

Q160. How would you create an SQL database with sharding capabilities for geographical and time _ series information?

Ans.

To create an SQL database with sharding capabilities for geographical and time-series information, follow these steps:

  • Determine the sharding key based on the data's geographical and time-series attributes

  • Choose a sharding strategy such as range, hash, or composite

  • Create multiple database shards and distribute data based on the sharding key

  • Implement a load balancer to evenly distribute queries across shards

  • Ensure data consistency and availability through replication and failov...read more

Add your answer

Q161. SQL- write a syntax to create table

Ans.

SQL syntax to create a table

  • Use CREATE TABLE statement

  • Specify table name and column names with data types

  • Add constraints like primary key, foreign key, etc. if needed

Add your answer

Q162. What is Pattern Matching in SQL

Ans.

Pattern matching in SQL is a technique used to search for specific patterns within strings or data.

  • Pattern matching is commonly used with the LIKE operator in SQL to search for specific patterns within text data.

  • Wildcards such as % (percent sign) and _ (underscore) are used in conjunction with the LIKE operator to represent unknown characters or sequences.

  • For example, 'SELECT * FROM table WHERE column LIKE 'A%'' would return all rows where the column starts with the letter 'A...read more

Add your answer

Q163. Diff between like and rlike

Ans.

The main difference between like and rlike is that like is used for simple pattern matching using wildcards, while rlike is used for regular expression pattern matching.

  • like is used for simple pattern matching with % representing zero or more characters and _ representing a single character

  • rlike is used for more complex pattern matching using regular expressions

  • Example: 'abc' like 'a%' will return true, while 'abc' rlike '^a.*$' will also return true

Add your answer
Frequently asked in

Q164. What is super key in sql

Ans.

A super key is a set of attributes that uniquely identifies each tuple in a table.

  • A super key can contain more attributes than necessary to uniquely identify a tuple.

  • Example: {ID, Name} can be a super key for a table with attributes {ID, Name, Age}.

  • Super keys are used in database design to ensure data integrity.

Add your answer

Q165. Difference between @qualifier and @ primary in soring

Ans.

The @Qualifier annotation is used to specify which bean should be autowired when multiple beans of the same type are present. The @Primary annotation is used to give higher priority to a bean when multiple beans of the same type are present.

  • Use @Qualifier when you have multiple beans of the same type and need to specify which one to inject.

  • Use @Primary to give higher priority to a bean when multiple beans of the same type are present.

  • Example: @Qualifier("beanName") vs @Primar...read more

Add your answer

Q166. What is the LINQ equivalent of LEFT JOIN in SQL

Ans.

LINQ equivalent of LEFT JOIN is DefaultIfEmpty()

  • Use DefaultIfEmpty() method to perform LEFT JOIN in LINQ

  • Use into keyword to create a temporary variable for the join

  • Example: var result = from a in tableA

  • join b in tableB on a.Id equals b.Id into temp

  • from b in temp.DefaultIfEmpty()

  • select new { a.Id, b.Name }

Add your answer

Q167. What is CDC in sql service?

Ans.

CDC stands for Change Data Capture in SQL Server.

  • CDC is a feature in SQL Server that captures changes made to data in a table.

  • It allows you to track insert, update, and delete operations on the table.

  • CDC uses a separate table to store the changes made to the tracked table.

  • It is useful for auditing, data replication, and data warehousing purposes.

Add your answer

Q168. What is SQLi its types?

Ans.

SQLi stands for SQL Injection. It is a type of cyber attack where an attacker injects malicious SQL code into a vulnerable website.

  • SQLi allows attackers to access sensitive data from a website's database

  • There are three types of SQLi: In-band, Inferential, and Out-of-band

  • In-band SQLi is the most common type and involves using the same communication channel to launch the attack and retrieve data

  • Inferential SQLi involves using logical deductions to infer information from the dat...read more

Add your answer

Q169. Write SQL commands to create a student table with ID and name, columns, and the data and designing order of ID

Ans.

Creating a student table in SQL with ID and name columns and setting the order of ID

  • Use CREATE TABLE command to create the student table

  • Specify ID and name columns with their data types

  • Set the ID column as the primary key to enforce uniqueness and order

Add your answer
Frequently asked in

Q170. What is isolation in sql?

Ans.

Isolation in SQL refers to the ability to control the visibility of changes made by one transaction to other transactions.

  • Isolation levels in SQL determine how transactions interact with each other

  • Higher isolation levels provide more control over visibility of changes

  • Common isolation levels include READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, and SERIALIZABLE

Add your answer

Q171. Explain keys in SQL.

Ans.

Keys in SQL are used to establish relationships between tables and ensure data integrity.

  • Keys are used to uniquely identify each record in a table.

  • Primary keys are used to identify each record in a table and must be unique.

  • Foreign keys are used to establish relationships between tables.

  • Composite keys are used when a combination of columns is needed to uniquely identify a record.

  • Keys ensure data integrity by preventing duplicate records and maintaining referential integrity.

Add your answer
Frequently asked in

Q172. What is use of SQL in data analytics.

Ans.

SQL is used in data analytics to query, manipulate, and analyze data stored in databases.

  • SQL is used to retrieve data from databases using queries.

  • It can be used to filter, sort, and aggregate data for analysis.

  • SQL can also be used to join multiple tables to combine data from different sources.

  • Common SQL functions like SUM, AVG, COUNT, etc. are used in data analytics.

  • Example: SELECT * FROM sales_data WHERE date BETWEEN '2021-01-01' AND '2021-12-31';

Add your answer
Frequently asked in

Q173. Why should use entity framework rather than writing sql query?

Ans.

Entity Framework provides a higher level of abstraction, simplifies database operations, improves productivity, and reduces code complexity.

  • Entity Framework abstracts away the underlying database, allowing developers to work with a higher level of abstraction.

  • It simplifies database operations by providing an object-oriented approach to data access.

  • Entity Framework improves productivity by reducing the amount of code needed to perform database operations.

  • It reduces code comple...read more

Add your answer
Frequently asked in

Q174. Explain advance sql functions used in your projects

Ans.

I have used advanced SQL functions like window functions, CTEs, and stored procedures in my projects.

  • Utilized window functions like ROW_NUMBER(), RANK(), and NTILE() for analytical queries

  • Implemented Common Table Expressions (CTEs) for recursive queries and code readability

  • Developed complex logic using stored procedures for data manipulation and business logic

  • Used functions like LEAD(), LAG(), and OVER() for advanced data analysis

Add your answer

Q175. What is SQL Locks

Ans.

SQL locks are mechanisms used to control access to data in a database to prevent conflicts and ensure data integrity.

  • SQL locks are used to prevent multiple users from accessing or modifying the same data simultaneously.

  • There are different types of SQL locks such as shared locks, exclusive locks, and update locks.

  • Locks can be applied at different levels such as row-level, page-level, or table-level.

  • For example, a shared lock allows multiple users to read data but only one user...read more

Add your answer

Q176. On what 3 conditions are two tables joined in sql?

Ans.

Tables are joined in SQL based on common columns, specified conditions, and join type.

  • Common columns: Tables are joined based on columns that have the same values in both tables.

  • Specified conditions: Join conditions are specified using the ON keyword in SQL.

  • Join type: Different types of joins like INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN determine how the tables are joined.

Add your answer

Q177. What is ETL in SQL?

Ans.

ETL stands for Extract, Transform, Load in SQL. It is a process of extracting data from various sources, transforming it into a usable format, and loading it into a target database.

  • Extract: Retrieving data from different sources such as databases, files, APIs, etc.

  • Transform: Cleaning, filtering, and structuring the extracted data to fit the target database schema.

  • Load: Loading the transformed data into the target database for analysis and reporting.

  • Example: Extracting custome...read more

Add your answer

Q178. rate ur self in sql and snowflake

Ans.

I rate myself highly in SQL and Snowflake, with extensive experience in both technologies.

  • Proficient in writing complex SQL queries for data manipulation and analysis

  • Skilled in optimizing queries for performance and efficiency

  • Experienced in working with Snowflake for data warehousing and analytics

  • Familiar with Snowflake's unique features such as virtual warehouses and data sharing

Add your answer
Frequently asked in

Q179. What is cluster in Sql server.

Ans.

A cluster in SQL Server is a group of servers that work together to provide high availability and scalability.

  • A cluster is used to ensure that a database is always available, even if one server fails.

  • It allows for load balancing across multiple servers to improve performance.

  • SQL Server supports two types of clusters: failover clusters and active-active clusters.

  • Failover clusters have one active server and one or more standby servers that take over if the active server fails.

  • A...read more

Add your answer
Frequently asked in

Q180. what are all the clauses available in sql

Ans.

SQL clauses are used to perform specific actions in a SQL query.

  • SELECT: retrieves data from a database

  • FROM: specifies the table(s) to retrieve data from

  • WHERE: filters the data based on specified conditions

  • GROUP BY: groups the data based on specified columns

  • HAVING: filters the grouped data based on specified conditions

  • ORDER BY: sorts the data based on specified columns

  • JOIN: combines rows from multiple tables based on related columns

  • INSERT INTO: inserts new data into a table

  • UPD...read more

Add your answer

Q181. How sql execute

Ans.

SQL executes by parsing the query, creating an execution plan, and retrieving data from the database.

  • SQL query is sent to the database server for processing

  • Database server parses the query to understand the operations to be performed

  • An execution plan is created to optimize the query performance

  • Data is retrieved from the database based on the query criteria

  • Results are returned to the user

Add your answer
Frequently asked in

Q182. What is Table variable

Ans.

Table variable is a variable that can hold a set of data like a table in a database.

  • Table variables are declared using the DECLARE statement in SQL Server.

  • They can be used to store temporary data that can be used in a query or a stored procedure.

  • Table variables are stored in memory and are only visible within the scope of the code block in which they are declared.

  • They can be used as an alternative to temporary tables.

  • Example: DECLARE @myTableVariable TABLE (ID INT, Name VARCH...read more

Add your answer
Frequently asked in

Q183. Q1/- How to extract data from database

Ans.

To extract data from a database, one can use SQL queries or programming languages like Python or R.

  • Use SQL queries to extract data from a database

  • Use programming languages like Python or R to extract data from a database

  • Connect to the database using appropriate credentials

  • Identify the tables and columns from which data needs to be extracted

  • Write the query or code to extract the data

  • Save the extracted data in a desired format

Add your answer

Q184. How to use Rank function?

Ans.

Rank function is used to assign a rank to each row within a partition of a result set.

  • Use the RANK() function in SQL to assign a unique rank to each row within a partition.

  • The rank is determined by the ORDER BY clause specified in the query.

  • If two rows have the same value, they will have the same rank, and the next row will have a rank that is incremented by the number of tied rows.

Add your answer
Frequently asked in

Q185. What is Temporary tables in SQL.

Ans.

Temporary tables are tables that exist temporarily in the database and are used to store intermediate results.

  • Temporary tables are created using the CREATE TABLE statement with the # symbol before the table name.

  • They are useful for storing intermediate results during complex queries or procedures.

  • Temporary tables are automatically dropped when the session that created them ends or when the connection is closed.

  • They can be used to improve performance by reducing the number of ...read more

Add your answer

Q186. what is sql and basic commands of sql

Ans.

SQL is a programming language used to manage and manipulate relational databases.

  • Basic commands include SELECT, INSERT, UPDATE, DELETE, CREATE, and DROP.

  • SELECT is used to retrieve data from a database.

  • INSERT is used to add new data to a database.

  • UPDATE is used to modify existing data in a database.

  • DELETE is used to remove data from a database.

  • CREATE is used to create a new database or table.

  • DROP is used to delete a database or table.

Add your answer
Frequently asked in

Q187. How do you secure your data in SQL server

Ans.

Secure data in SQL server using encryption, access control, and regular backups.

  • Encrypt sensitive data using TDE or column-level encryption

  • Implement access control using roles and permissions

  • Regularly backup data to prevent loss or corruption

  • Use strong passwords and limit access to the server

  • Monitor for suspicious activity and implement auditing

Add your answer

Q188. What do you know about unique keyword in sql

Ans.

UNIQUE keyword in SQL is used to ensure that all values in a column are unique.

  • Used in CREATE TABLE statement to define a column as unique

  • Prevents duplicate values in the specified column

  • Can be used with multiple columns to create composite unique keys

Add your answer

Q189. What is the process of SQL Developer?

Ans.

SQL Developer is a tool used to develop and manage databases using SQL queries.

  • SQL Developer allows users to write and execute SQL queries.

  • It provides a visual interface for database design and management.

  • Users can view and edit table structures, import and export data, and generate reports.

  • SQL Developer also includes features for debugging and performance tuning.

  • Examples: Writing a SELECT query to retrieve data from a table, creating a new database schema.

Add your answer

Q190. What is denormalization( SQL)

Ans.

Denormalization is the process of adding redundant data to a database to improve read performance.

  • Reduces the need for joins, improving query performance

  • Increases data redundancy but can improve read performance

  • Commonly used in data warehousing and reporting applications

Add your answer
Frequently asked in

Q191. Whats is Temporary Table in SQL?

Ans.

Temporary table in SQL is a table that exists temporarily and is automatically deleted when the session ends.

  • Temporary tables are created using CREATE TEMPORARY TABLE statement.

  • They are useful for storing intermediate results during complex queries.

  • Temporary tables are only visible to the current session and are automatically dropped when the session ends.

Add your answer

Q192. What is hard and soft parse

Ans.

Hard parse is when SQL statement is parsed every time it is executed. Soft parse is when SQL statement is parsed only once.

  • Hard parse is resource-intensive and can slow down performance.

  • Soft parse is faster and more efficient.

  • Hard parse occurs when there is a syntax error or when the SQL statement is not in the shared pool.

  • Soft parse occurs when the SQL statement is already in the shared pool.

  • Hard parse can be avoided by using bind variables.

  • Soft parse can be affected by chan...read more

Add your answer

Q193. Delete Duplicate records for Sql Server ?

Ans.

Use a common table expression (CTE) with ROW_NUMBER() function to delete duplicate records.

  • Use a CTE to assign a row number to each record partitioned by the columns that define duplicates

  • Delete records where the row number is greater than 1

  • Example: WITH CTE AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY column1, column2 ORDER BY column1) AS rn FROM table_name) DELETE FROM CTE WHERE rn > 1

Add your answer
Frequently asked in

Q194. What are the windows functions in sql

Ans.

Window functions in SQL are used to perform calculations across a set of rows that are related to the current row.

  • Window functions are used to calculate running totals, moving averages, and rank values.

  • They are applied to a set of rows defined by an OVER clause.

  • Examples of window functions include ROW_NUMBER, RANK, DENSE_RANK, and NTILE.

Add your answer
Frequently asked in

Q195. How to do bulk entry from excel to SQL.

Ans.

Use SQL Server Integration Services (SSIS) to import data from Excel to SQL Server.

  • Create a new SSIS package in SQL Server Data Tools.

  • Use the Excel Source component to read data from the Excel file.

  • Map the columns from Excel to the destination SQL Server table using the OLE DB Destination component.

  • Run the SSIS package to import the data in bulk.

Add your answer

Q196. what is injection in sql ?

Ans.

Injection in SQL is a technique used by hackers to insert malicious code into a database through user input.

  • Injection attacks occur when user input is not properly sanitized or validated

  • Attackers can use injection to steal data, modify data, or even delete data

  • Preventing injection attacks involves using prepared statements and input validation

Add your answer

Q197. What is predicate

Ans.

Predicate is a function that returns a boolean value based on input parameters.

  • Predicate is commonly used in programming languages to filter data based on certain conditions.

  • It can be used with higher-order functions like filter, map, and reduce.

  • Example: A predicate function in JavaScript that checks if a number is even: function isEven(num) { return num % 2 === 0; }

Add your answer
Frequently asked in

Q198. Connect anyDesk and perform sql operation on company pc.

Ans.

Use AnyDesk to remotely connect to company PC and perform SQL operations.

  • Install AnyDesk on both devices for remote connection.

  • Connect to company PC using AnyDesk ID and password.

  • Open SQL client on company PC to perform operations.

  • Execute SQL queries as needed for database operations.

Add your answer

Q199. Explain how an Select statement is parsed in Oracle database

Ans.

The parsing of a SELECT statement in Oracle database involves several steps.

  • The statement is first checked for syntax errors.

  • The query is then parsed to identify the objects involved and their relationships.

  • The optimizer determines the most efficient execution plan.

  • The plan is executed and the result set is returned.

Add your answer
Frequently asked in

Q200. How to edit in database with the help of query?

Ans.

To edit in a database with a query, use the UPDATE statement with appropriate conditions and values.

  • Use the UPDATE statement to modify data in a database table

  • Specify the table name and set the new values using the SET keyword

  • Use the WHERE clause to specify the conditions for the update

  • Example: UPDATE employees SET salary = 50000 WHERE department = 'IT'

Add your answer
1
2
3
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.4k Interviews
3.8
 • 8.1k Interviews
3.6
 • 7.5k Interviews
3.7
 • 5.6k Interviews
3.8
 • 5.6k Interviews
3.7
 • 4.7k Interviews
3.5
 • 3.8k Interviews
3.5
 • 3.8k Interviews
3.8
 • 2.9k Interviews
3.8
 • 2.8k Interviews
View all
SQL Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter