0% found this document useful (0 votes)
7 views

sql interviewquestions (1)

The document explains key SQL concepts including primary keys, foreign keys, and the differences between DELETE and TRUNCATE commands. It also covers JOIN types, NULL values, normalization, indexes, aliases, and the differences between WHERE and HAVING clauses. Additionally, it describes SQL views and various types of relationships in SQL.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

sql interviewquestions (1)

The document explains key SQL concepts including primary keys, foreign keys, and the differences between DELETE and TRUNCATE commands. It also covers JOIN types, NULL values, normalization, indexes, aliases, and the differences between WHERE and HAVING clauses. Additionally, it describes SQL views and various types of relationships in SQL.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.What is a primary key in SQL?

It is a unique identifier for each record in a table. It ensures that each row in the table
has a distinct and non-null value in the primary key column. Primary keys enforce data
integrity and create relationships between tables.

2. What is a foreign key?

It is a field in one table referencing the primary key in another. It establishes a


relationship between the two tables, ensuring data consistency and enabling data
retrieval across tables.

3. Explain the difference between DELETE and TRUNCATE commands

The DELETE command is used by professionals to remove particular rows from a table
based on a condition, allowing you to selectively delete records. TRUNCATE, on the
other hand, removes all rows from a table without specifying conditions. TRUNCATE is
faster and uses fewer system resources than DELETE but does not log individual row
deletions

4. What is a JOIN in SQL, and what are its types?

A JOIN operation merges information from two or more tables by utilizing a common
column that links them together. Various types of JOINs exist, like INNER JOIN, LEFT
JOIN, RIGHT JOIN, and FULL JOIN. These JOIN variations dictate the manner in which
data from the involved tables is paired and retrieved.
5. What do you mean by a NULL value in SQL?

A NULL value in SQL represents the absence of data in a column. It is not the same as
an empty string or zero; it signifies that the data is missing or unknown. NULL values
can be used in columns with optional data or when the actual data is unavailable6.

6. Explain the differences between SQL and NoSQL databases.

SQL databases are characterized by their use of structured tables and strict adherence
to a predefined schema, making them ideal for managing structured data with a strong
focus on data consistency and transaction support. In contrast, NoSQL databases are
non-relational and excel in handling unstructured or semi-structured data, frequently
employed for scalable, distributed, and adaptable data storage solutions.

7.What is normalization in sql?

Normalization is the process of organizing data in a database to minimize redundancy


and dependency by dividing large tables into smaller, related tables. It ensures data
consistency, improves database performance, and makes the data easier to maintain
and query.

8. What are indexes in SQL?

Indexes are a method of retrieving data from the data base in a faster way.it
help me in locating specific rows.it helps in optimizing query perfomance.
9.What is alias in sql?

An alias in SQL is a temporary name assigned to a table or column for the


duration of a query.it is useful in readability and management of sql query

10. Describe the difference between WHERE and HAVING in SQL

• The WHERE clause is used to filter rows before any grouping or


aggregation is done. It cannot be used with aggregate functions like
COUNT(), SUM(), or AVG().
• The HAVING clause is used to filter groups after the GROUP BY operation
and aggregation are performed. It works specifically with aggregated data
and can be used with aggregate functions.

11. What is a view in SQL?

An SQL view is essentially a virtual table that derives its data from the outcome of a
SELECT query. It does not store data itself, but rather stores the SQL query used to
retrieve the data from one or more tables.

12. Write down various types of relationships in SQL?

There are various relationships, namely:

• One-to-One Relationship.
• One to Many Relationships.
• Many to One Relationship.
• Self-Referencing Relationship

You might also like