Ques.26. What is the difference between delete, truncate and drop command?
Ans. The difference between the Delete, Truncate and Drop command is -
Ques.27. What are the different types of joins in SQL?
Ans. Joins are used to combine records from multiple tables. The different types of joins in SQL are-
Ques.28. What is the difference between cross join and full outer join?
Ans. A cross join returns cartesian product of the two tables, so there is no condition or on clause as each row of tabelA is joined with each row of tableB whereas a full outer join will join the two tables on the basis of condition specified in the on clause and for the records not satisfying the condition null value is placed in the join result.
Ques.29. What are difference between having and where clause?
Ans. A 'where' clause is used to fetch data from database that specifies a particular criteria (specified after the where clause). Whereas a 'having' clause is used along with 'groupby' to fetch data that meets a particular criteria specified by the aggregate function.
For example - for a table with Employee and Project fields, if we want to fetch Employee working on a particular project P2, we will use 'where' clause-
Now if we want to fetch Employees who are working on more than one project, we will first have to group the Employee column along with count of project and than the 'having' clause can be used to fetch relevant records-
Ques.30. What is the difference between Union and Union All command?
Ans. The fundamental difference between Union and Union All command is, Union is by default distinct i.e. it combines the distinct result set of two or more select statements. Whereas, Union All combines all the rows including duplicates in the result set of different select statements.
Ques.31. Define the select into statement.
Ans. Select into statement is used to directly select data from one table and insert into other, the new table gets created with same name and type as of the old table-
Ques.32. What is a View in SQL?
Ans. A view is virtual table, it is a named set of SQL statements which can be later referenced and used as a table.
Ques.33. Can we use 'where' clause with 'groupby'?
Ans. Yes, we can use 'where' clause with 'groupBy'. The rows that doesn't meet the where conditions are removed first and then the grouping is done based on the groupby column.
Ques.34. What is Database Normalisation?
Ans. Database normalisation is the process of organisation of data in order to reduce the redundancy and anamalies in the database. We have different Normalisation forms in SQL like - First Normal Form, Second Normal Form, Third Normal Form and BCNF.
Ques.35. Explain First Normal Form(1NF).
Ans. According to First Normal Form a column cannot have multiple values, each value in the columns must be atomic.
Ques.36. Explain Second Normal Form(2NF).
Ans. For a table to be considered in Second Normal Form, it must follow 1NF and no column should be dependent on the primary key.
Ques.37. Explain Third Normal Form(3NF).
Ans. For a table to be Third Normaa Form, it must follow 2NF and each non-prime attribute must be dependent on primary key of the table.
For each functional dependency X -> Y either-
X should be the super key or Y should be the prime attribute(part of one of the candidate keys) of table
Ques.38. Explain Boyce and Codd Normal Form(BCNF).
Ans. BCNF is the advanced or stricter version of 3NF.
For each functional dependency X -> Y-
X should be the super key
Ques.39. What are transactions in SQL?
Ans. Transaction is a set of operations performed in a logical sequence. It is executed as a whole, if any statement in the transaction fails, the whole transaction is marked as failed and not committed to the database.
Ques.40. What are ACID properties?
Ans. ACID properties refers to the four properties of transactions in SQL-
Ques.41. What are locks in SQL?
Ans. Locks in SQL are used for maintaining database integrity in case of concurrent execution of same piece of data.
Ques.42. What are the different types of locks in database?
Ans. The different types of locks in database are-
Ques.43. What are aggregate functions in SQL?
Ans. Aggregate functions are the SQL functions which return a single value calculated from multiple values of columns. Some of the aggregate functions in SQL are-
Ques.44. What are scalar functions in SQL?
Ans. Scalar functions are the functions that return a single value by processing a single value in SQL. Some of the widely used SQL functions are-
Ques.45. What is a coalesce function?
Ans. Coalesce function is used to return the first not NULL value out of the multiple values or expressions passed to the coalesce function as parameters.Example-
COALESCE(NULL, NULL, 5, 'ArtOfTesting') will return the value 5.
COALESCE(NULL, NULL, NULL) will return NULL value as no not NULL value is encountered in the parameters list.
Ques.46. What are cursors in SQL?
Ans. Cursors are objects in SQL that are used to traverse the result set of a SQL query one by one.
Ques.47. What are stored procedures? Explain there advantages?
Ans. Stored procedures are SQL procedures(bunch of SQL statements) that are stored in the database and can be called by other procedures, triggers and other applications.
The advantages of stored procedure are-
Ques.48. What are triggers in SQL?
Ans. Triggers are special type of stored procedures that get executed when a specified event occurs. Syntax-
Ques.49. What are orphan records?
Ans. Orphan records are the records having foreign key to a parent record which doesn't exist or got deleted.
Ques.50. How can we remove orphan records from a table?
Ans. In order to remove orphan records from database we need to create a join on the parent and child tables and then remove the rows from child table where id IS NULL.
*Remember: Delete with joins requires name/alias before from clause in order to specify the table of which data is to be deleted.