SQL JOIN allows access to records of other table based on the given conditions between two tables Ex: If we are provided with the department ID of each employee, then we can use the department ID of the employee table to merge with the department ID of the department table to access department names UNION operation allows addition of 2 similar data sets to create a resulting set that contains all the data from the source data sets Ex: If we are provided with 2 employee tables of the same structure, we can UNION them to create a singular result that will contain all employee from both the table
Correct Answer: In a nutshell, a temp table is a temporary storage structure It means you can use a temp table to store data temporarily so you can manipulate and change it before it reaches its destination format In table_usergender column change ?male to female? and ?female to male? in one SQL statement UPDATE table_user SET gender = CASE gender WHEN ?male? THEN ?female? WHEN ?female? THEN ?male? ELSE gender END
2. Which TCP/IP port does SQL Server run on? How can it be changed?
Correct Answer: One can use simple conditions like >= and <=, or use between/and but the trick here is to know your exact data type - Sometimes date fields contain time and that is where the query can go wrong so it is recommended to use some date related functions to remove the time issue In SQL Server common function for accomplishing the task datediff () function - Interviewees also have to be aware of different time zones and server time zone -To increase query performance you may still want to use between however you should be aware of proper format you should use if not it might misbehave during filtering
4. How will you find the 3rd max salary in the employment table?
Correct Answer: A spanning tree is a tree associated with a network All the nodes of the graph appear on the tree once A minimum spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized
Correct Answer: The knowledge of Joins is a MUST for every interviewee Most SQL programmers have used inner join and outer join[left/right]; but the catch point here is to also mention cross join and self-join
7. What are user defined data-types and when do you use them?
Correct Answer: User defined data-types in SQL is an extension to the base SQL server data-types by provision of a descriptive name We use them to format the database and segregate specific repetitions of rows and columns in the database
8. What are the properties and different Types of Sub-Queries?
Correct Answer: Properties of Sub-Query - A sub-query must be enclosed in the parenthesis - A sub-query must be put in the right hand of the comparison operator, and - A sub-query cannot contain an ORDER-BY clause - A query can contain more than one sub-query Types of Sub-Query - Single-row sub-query, where the sub-query returns only one row - Multiple-row sub-query, where the sub-query returns multiple rows, and - Multiple column sub-query, where the sub-query returns multiple columns
Correct Answer: Catalog views return information that is used by the SQL Server Database Engine Catalog Views are the most general interface to the catalog metadata and provide the most efficient way to obtain, transform, and present customized forms of this information All user- available catalog metadata is exposed through catalog views