1. What is the difference between Delete and Drop commands?
Delete Command:
Delete Command:
- Delete removes the data from the table and the structure of the table will be retained.
- This is a DML command.
- Rollback is possible.
- Drop permanently removes both the data as well as the structure of the table.
- This is a DDL command.
- Rollback is not possible.
2. What is the difference between Delete and Truncate commands?
Delete Command:
- Delete command deletes only the rows from the table based on the condition given in the where clause and also it deletes all the rows from the table if no condition is specified.
- It does not free the space containing the table.
Truncate Command:
- Truncate command is used to delete all the rows from the table and free the space containing the table.
3. What is a primary key?
A primary key is a combination of fields which uniquely specify a row. Primary key values cannot be NULL.
4. What is a foreign key?
The relationship needs to be created between two tables by referencing foreign key with the primary key of another table.
5. What is Joins in SQL?
Joins are used to combines the results of two tables. It combines the data based on the relationship between tables.
6. What are the different types of joins in SQL?
Following are the most commonly used joins in SQL:
- Inner Join
- Right Join
- Left Join
- Full Join
- Left Outer Join
- Right Outer Join
7. What is Inner Join in SQL?
Inner join returns matching rows between the two tables.
8. What is the difference between BETWEEN and IN condition operators?
The BETWEEN operator is used to display the rows based on a range of values.
Examples:
Select * from blogs where pageviews BETWEEN 10 AND 20;
The IN condition operator is used to check for values contained in a specific set of values.
Examples:
Select * from blogs where country IN ('Germany', 'France', 'UK');
9. Is it possible for a table to have more than one foreign key?
Yes, A table can have many foreign keys and only one primary key.