SQL Server Interview Question -Part 2

September 14th, 2010 by aabhaanjan

What is joins ?

Joins a way to get data from multiple tables . By join, you can retrieve the data from two or more tables based on logical relationship between tables .

Different types of joins :-

  1. Inner join :-Inner join get the matches record from both the tables .
  2. Outer Join
    1. Left Outer Join :- The Result sets of left outer join get all the records/rows from the left tables . When the rows from left table has no matching record from right table , then associated rows show null values for all columns.
    2. Right Outer join :- The result sets of the right outer join contain all the records / rows from the right tables .
    3. Full Join or Full outer  Join :- A full outer join returns all rows in both the left and right tables.
  3. Cross Join :- Cross joins return all rows from the left table. Each row from the left table is combined with all rows from the right table. Cross joins are also called Cartesian products.
  4. Self Join :- if we want to use two instance of the same table is calld self join .

What is Constraints in SQL Server ?

A constraints is a property assigned to a column or a set of column in a table that prevent certain types of inconsistency data. SQL Server constraints allows you to enforce rules in your database .

How many types of constraints in SQL Server ?

Basically there are six types of constraints supported by SQL Server .

  1. UNIQUE Constraints :-A Unique constraints assigned to a column or a set of column in a table that a column may not contain duplicate values .Unique Key constraints uniquely identify the each row .Unique Key Constarints support NULL value also .
  2. Primary Key Constraints :- A Primary Key Constraints assigned to a column or a set of column to uniquely identify the each row from table . You can create only one primary key constraints in table . Primary Key not support NULL values .
  3. Foreign Key Constraints :- Foreign Key are fields in table that match the primary key to other table .Foreign Key describe the referential integrity concepts .Apart of these constraints there are check constraints , not null constraints ,default constraints  etc.

What is Sub query ?

A Sub Query is T SQL Statement that is nested inside other sql query .

Tags: , , , , , , , , , ,