0% found this document useful (0 votes)
10 views6 pages

Demo 4 Sept23

SQL Demo 4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Demo 4 Sept23

SQL Demo 4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

create database [database]

use [database]

create table t1 ([emp id] int)

--************************************************************
Create database hospital

Use hospital

create table Doctors ( DoctorID, FirstName, LastName, Specialization, Age)

--************************************************************
create table t2
(
id int ,nam varchar(max), adds nchar(100)
)

insert into t2 values


(100, 'alpha','delhi')
go 10000000

alter table t2
add age int

select * from t2

alter table t2
drop column nam

alter table t2
alter column id varchar(100)

--************************************************************
sp_help database_object

--******************************************

Create database Organisation

use Organisation

Create table Employee


(
eid int , ename varchar(max), eage int,
edob date , gender char, salary float )

insert into employee values


(101,'Alpha',21,'2000-12-10','M',4567.89),
(103,'delta',24,'2000-12-10','M',7878.89),
(104,'charlie',24,'2000-12-10','M',7878.89),
(105,'delta',24,'2000-12-10','M',7878.89),
(106,'echo',24,'2000-12-10','M',7878.89),
(107,'delta',24,'2000-12-10','M',7878.89),
(107,'fox',24,'2000-12-10','M',7878.89),
(108,'ji',24,'2000-12-10','M',7878.89)

insert into employee (eage, edob, gender) values


(10,'2023-01-01','M')

--******************************************
select ename, datalength(ename) as byte from Employee

--******************************************
select * from Employee

--************************************************************
CREATE TABLE department
(
did INT ,
ename VARCHAR(50) ,
gender VARCHAR(50) ,
salary INT,
department VARCHAR(50)
)

INSERT INTO department VALUES


(1, 'David', 'Male', 5000, 'Sales'),
(4, 'Will', 'Male', 6500, 'Marketing'),
(8, 'Vince', 'Female', 6600, 'IT'),
(2, 'Jim', 'Female', 6000, 'HR'),
(3, 'Kate', 'Female', 7500, 'IT'),
(9, 'Jane', 'Female', 5400, 'Marketing'),
(10, 'Laura', 'Female', 6300, 'Finance'),
(11, 'Mac', 'Male', 5700, 'Sales'),
(5, 'Shane', 'Female', 5500, 'Finance'),
(6, 'Shed', 'Male', 8000, 'Sales'),
(7, 'Vik', 'Male', 7200, 'HR'),
(12, 'Pat', 'Male', 7000, 'HR'),
(13, 'Julie', 'Female', 7100, 'IT'),
(14, 'Elice', 'Female', 6800,'Marketing'),
(15, 'Wayne', 'Male', 6800, 'Finance')

INSERT INTO department VALUES


(1, 'Alpha', 'Male', 5000, 'Sales'),
(2, 'Lima', 'Female', 6000, 'HR'),
(3, 'Beta', 'Female', 7500, 'IT')

INSERT INTO department VALUES


(11, 'Alpha', 'Male', 5000, 'Sales')

INSERT INTO department VALUES


(17, 'Alpha', 'Male', 5000, 'Sales')
INSERT INTO department VALUES
(21, 'beta', 'Male', 5000, 'Sales'),
(22, 'Lima', 'Female', 6000, 'HR'),
(23, 'Beta', 'Female', 7500, 'IT')
--ORDER BY (Asc, desc)
--ASC
select * from department
order by did asc

select * from department


order by did asc,ename asc

select * from department


order by did,ename
--Desc
select * from department
order by did desc,ename desc

select * from department


order by did asc,ename desc

Select * from department


order by ename desc,did asc

--************************************************************
=, 1= , > ,<,>=,<=

-- =
Select * delete from department
where did =1
-- !=, <>
Select * from department
where did !=1

Select * from department


where did <> 1

-->=
Select * from department
where did >5

Select * from department


where did >=5
--<=
Select * from department
where did <7

Select * from department


where did <=5
order by did
--************************************************************
Select * from department
where did =1 and gender='female' and department='sales'

Select * from department


where did =1 or department='sales' or gender='female'
order by did

Select * from department


where did =1 and gender='MALE' OR department='IT'
ORDER BY DID

Select * from department


where
did =101 and gender='MALE' --false
OR
department='IT' and gender ='male' --false
ORDER BY DID
--**************************************
Select * from department
where
did =102 or gender='feMALE' and department='IT' or gender ='male'
ORDER BY gender

Select * from department


where
(department='hr' or gender='female') --false --grouping
and
(department='IT' or gender ='male' ) --false
ORDER BY DID

Select * from department


where
did=102 or gender='female' AND department='IT' or Salary=8000

--************************************************************
Select * from department
where did=1 or did=12 or did= 7 or did= 9

--IN
Select * from department
where did in (1,3,7,19,11,999, 2006)
order by did

--NOt IN
Select * from department
where did!=1 and did!=12 and did!= 7 and did!= 9
order by did

Select * from department


where did not in (1,3,7,19,11,999, 2006)
order by did
--char/ varchar/ date column filteration
Select * from department
where ename in ('Lima','Will','Shane','Shed','Vince')
order by did

Select * from department


where ename not in ('Lima','Will','Shane','Shed','Vince')
order by did

--************************************************************
--Between
----int/char/ varchar/ date column filteration
Select * from department
where did between 6 and 11
order by did

Select * from department


where ename between 'a' and 'am'
order by ename

Select * from department


where ename between 'm' and 'vZ'
order by ename

insert into department([eid], [ename], [eage], [edob], [gender], [salary])


values (213,'test','male',6732,'it')

--like % _

1 and 5

12345

d, e,f,g,h

a
ab
abc
abcd

insert into department (ename)


values ( 'az'),('ab'),('abc'),('abcd')

select ename from department

where ename between 'a' and 'azb'

a
ab
abc
abcd
--******************************************************
----int/char/ varchar/ date column filteration
--'%a' you dont know what comes before
select * from department
where did like '%1%'

select * from department


where ename like '%an%'

select * from department


where ename like '%j%'

select * from department


where ename like '%e%'

select * from department


where ename like 'S%'

select * from department


where ename like '%e'

select * from department


where salary like '%75%'

-- Wildcard _ represent 1 character data

select * from department


where ename like 'J__'

select * from department


where ename like '_i_'

select * from department


where ename like 'v__'

You might also like