Learn How to Create Table, Insert data in table and use select querys SQL Server with Example

 Learn SQL Server with Example

FIRST WE CREATE TABLE

create table EMP

(

ENAME varchar(50) null,

DEPT_NAME varchar(50) null,

DESTINATION varchar(50) null,

SALARY varchar(50) null,

DATE_OF_JOIN date null DEFAULT GETDATE()

)


NOW NEED TO INSERT DATA

insert into EMP(ENAME,DEPT_NAME,DESTINATION,SALARY,DATE_OF_JOIN)

values('JHOHN','SALES','SALESMAN',20000,'2020-02-20'),

('LEZZY','SALES','SALESMAN',23000,'2023-05-05'),

('KAMAAL','ACCOUNT','CLERK',34000,'2019-07-04'),

('RITESH','ACCOUNT','MANAGER',40000,'2015-08-15'),

('SAXENA','SALES','SALESMAN',21000,'2015-10-10'),

('MANI','ACCOUNT','CLERK',34000,'2015-07-04')


After create and insert let's view data using diffrent -2 operators and logic.

If you want to show your all column and inside data you have to simply use select query with astrick(*) with from and table name , and then execute quiery using execute button or press "CTRL + F5".

for example

                       SELECT *FROM EMP



There are some questions set of querys:-

1) Query for find all the ENAME whose salary is less than "25000"?

    select *from EMP where SALARY < 25000


2) Query for all employees details working with SALES dept with designation "salesman"?

    select *from EMP where DESTINATION='salesman'


3) Query for all employees whose name start with 'M'?

    select *from EMP where ENAME like'M%'








4) Query for find total no of employees whose work Account department?

    select *from EMP where DEPT_NAME='account'

    


5) Query for find details of employees whose salary is between 30000 to 40000?

    select *from EMP where SALARY between 30000 and 40000

    






6) Query for sort EMP table by 'ENAME'?

    select *from EMP order by ENAME

with order by you can use asc for accending order and desc for descending order, SQL use by default accesnding order.

        


7) Query for sort EMP table by salary in desc order?

    select *from EMP order by SALARY desc

    

8) Query for count total number of employees?

    select count(ENAME) as [Employees Count] from EMP


hope you understand.









Comments