Saturday, 11 June 2016

Question and Answers in Sql Server - Part 2



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

8. what is the varchar(n) and varchar(max) ?
        varchar(n) - Stores the n bytes length + 2 bytes
        varchar(max) - Stores the max bytes + 2 bytes.


9. What are the services present in the SQL SERVER ?
       Integration service, Reporting Service, Analysis Service,Full Text Search, Sql Server Agent, Sql Browser etc.


10. Create a Database :
      Now we create a HRMS DB to hold the HR details and tables.
      CREATE DATABASE HRMS
   USE HRMS
     

11. Create a Table :
      Now we are going to create a two tables one for employee another for maintain the employee salary details, how we are going to link the two tables based on the employee id. Create a id column in employee table as primary key , i.e no repeatation of values in the column values must be unique not allow any empty values, now create a employee salary table to id column as foreign key i.e this column refers the employee table id column because if the id is exists in the employee table then only it allows to insert the record in the EMPLOY_SALARY table otherwise it shows error that values is not present in the primary key column.


CREATE TABLE EMPLOYEE
  (
    ID      INT IDENTITY(1,1) PRIMARY KEY,
    NAME    VARCHAR(40),
    ADDRES  VARCHAR(250),
    CONTACT INT
  )

INSERT INTO EMPLOYEE(NAME,ADDRES,CONTACT)
VALUES ('SIVA','CHENNAI',222222)


INSERT INTO EMPLOYEE(NAME,ADDRES,CONTACT)
VALUES ('DANIEL','HYDERABAD',224332)


INSERT INTO EMPLOYEE(NAME,ADDRES,CONTACT)
VALUES ('LINC','US',72233)


CREATE TABLE EMPLOY_SALARY
  (
    ID INT FOREIGN KEY REFERENCES EMPLOYEE(ID),
    SALARY INT,
    GRADE CHAR(1)
  )


INSERT INTO EMPLOY_SALARY(ID,SALARY,GRADE)
VALUES (1,80000,'D')


SELECT * FROM EMPLOYEE



No comments:

Post a Comment