Saturday, 11 June 2016

Question and Answers in Sql Server - Part 3



In This post Let we see some important question and answers in Sql Server, which is a continuation of previous post.



12. What are the keys present in the SQL SERVER ?
        Keys present in Sql Server Click here to read.


13 What are the Constraint's present in the SQL SERVER ?

        Default constraint, Check Constraint, Unique Constraint , Null Constraint.

        Default constraint : The name of constraint itself explain the usage , it specifies a default value for a column if the value is not inserted.

        Check Constraint : This constraint  check the user inserted value against the check condition present in the table.

        Unique Constraint : Is use to identify the row in unique like primary key.

         Null Constriant : It allows the null values to the value of a column in table.


 EX:

  PRIMARY KEY    -- unique constraint   (for unique identify the row.)


  CHECK(age > 20 AND age < 50-- check constraint (while user insert a value in                                   a row this check constraint check the value                                       before insert)

  DEFAULT(25000)  -- Default constraint (if user doesnt enter the value for this                      column this default value will be taken and inserted)

  NULL     -- Null constraint allows null value if user doesnt enter the                           value



CREATE TABLE cons_emp
(
 id    INT PRIMARY KEY,   
 age   INT CHECK(age > 20 AND age < 50), 
 ADDRES VARCHAR(100) ,
 salary INT DEFAULT(25000),             
 passportno INT NULL                
)


INSERT INTO cons_emp (id,age) VALUES (1, 25)


Query to find out the constraint present in a DB


SELECT      OBJECT_NAME(OBJECT_ID) AS NAMEOFCONSTRAINT,
            SCHEMA_NAME(SCHEMA_ID) AS SCHEMANAME,
            OBJECT_NAME(PARENT_OBJECT_ID) AS TABLENAME,
            TYPE_DESC AS CONSTRAINTTYPE
FROM  SYS.OBJECTS
WHERE TYPE_DESC LIKE '%CONSTRAINT'
GO



The Database is work around with main four operation CRUD, To do that following keywords are important.

CREATE
DELETE
UPDATE 
SELECT

These keywords are used to operate in tables for data.

Table and Database are the two words where are the keywords are working on.


14. What are objects is used to work on Tables and database to process the data ?
       Function
       Stored Procedure
       Trigger


15 What are Mostly commonly keywords used in Database to do operations ?
       Create Database
       Alter  Database
       Drop Database


No comments:

Post a Comment