3 What is the difference between DROP and TRUNCATE commands?
If a table is dropped, all things associated with that table are dropped as well. This includes the relationships defined on the table with other tables, access privileges, and grants that the table has, as well as the integrity checks and constraints.
To create and use the table again in its original form, all the elements associated with the table need to be redefined.
However, if a table is truncated, there are no such problems as mentioned above. The table retains its original structure.
6 What is the use of the INTERSECT operator?
The INTERSECT operator helps combine two select statements and returns only those records that are common to both the select statements. So, after we get Table A and Table B over here, and if we apply the INTERSECT operator on these two tables, then we will get only those records that are common to the result of the select statements of these two tables.
Syntax:
Now, let us take a look at an example for the INTERSECT operator.
Output:
Output:
1 What is a primary key?
A primary key is used to uniquely identify all table records. It cannot have NULL values and must contain unique values. Only one primary key can exist in one table, and it may have single or multiple fields, making it a composite key.
Now, we will write a query for demonstrating the use of a primary key for the employee table:
Q What do you understand about stored procedures in T SQL?
Stored procedures in T SQL are collection statements stored within the database. They are prepared T SQL code that you can save and reuse repeatedly. They encapsulate oft-used queries, including conditional statements, loops, and other programming features.Â
Stored procedures hide direct T SQL queries from the code and improve the performance of database operations like deleting, selecting, and updating data. They are similar to functions in high-level programming languages.Â
Q What are the various types of SQL Joins?
Joins in SQL are of the following types:
Recommended Reading: Top SQL Joins Interview Questions and Answers you should practice.
5 State the differences between views and tables.
Views | Tables |
A view is a virtual table that is extracted from a database | A table is structured with a set number of columns and a boundless number of rows |
A view does not hold data itself | A table contains data and stores it in databases |
A view is utilized to query certain information contained in a few distinct tables | A table holds fundamental client information and cases of a characterized object |
In a view, we will get frequently queried information | In a table, changing the information in the database changes the information that appears in the view |