Search This Blog

Q51-Q55

Q51.  What is full join in sql?
Q52. What are different types of Triggers in SQL?
Q53. Can you call a function inside another function in sql?
Q54. Syntax of user defined scaler function in sql?
Q55. Difference between Char(4) and Varchar(4) ?
===================================================================================
Q51.  What is full join in sql?

Answer:
Full join also known as Full Outer Join. 
There are 3 outer joins left outer join(or left join), Right outer Join (or right join) and full outer join (or full join)

The combination result of left outer join and right outer join is full join.

Left outer join = all values of left table will be present and in case key is not found then null will be placed against that values. 

SELECT C.FirstName, C.LastName, O.OrderDate
  FROM Customer C
  FULL JOIN [Order] O ON C.Id = O.CustomerId
 ORDER BY O.OrderDate 


===================================================================================
Q52. What are different types of Triggers in SQL?

Answer:
A trigger is a special type of stored procedure in database that automatically invokes/runs/fires when an event occurs in the database server. A trigger uses the special table to keep a copy of the row which we have just inserted, deleted or modified.

There are three types of triggers in SQL Server.  
  1. DDL Trigger  - DDL events are CREATE, ALTER and DROP
  2. DML Trigger -  INSERT, UPDATE, and DELETE
  3. Logon Trigger
===================================================================================
Q53. Can you call a function inside another function in sql?

Answer:
Yes you can call a function inside a function.

In fact, you can call the current function inside the function, to cause a loop.
===================================================================================
Q54. Syntax of user defined scaler function in sql?

Answer:

CREATE FUNCTION Function_Name(@Parameter_Name Data_type, 
                                 .... @Parameter_Name Data_type
                             )
RETURNS Data_Type
AS
   BEGIN
      -- Function Body
      
      RETURN Data 
   END

===================================================================================
Q55. Difference between Char(4) and Varchar(4)

Answer:

Char:
1. Its of fixed length and if value is less than the size it will fill with blank spaces. 
2. Select Length(<<char variable>>) will always give the same size, which is the size of char variable. 

Varchar:
1. Its max length is fixed and value is small than only that part will be filled. 
2. Select Length(<<varchar variable>>) will always give the size by which it is filled. if the values is small than less size value will come

===================================================================================