0% found this document useful (0 votes)
41 views

Create Varchar Varchar Varchar Int

The document contains the SQL code to create three database tables - studies, software, and programmer. The studies table contains student records with their name, institute, course, and course fee. The software table contains records of software developed by programmers with their name, title, development language, cost, development cost, and units sold. The programmer table contains records of programmers with their name, date of birth, date of joining, gender, primary and secondary proficiency. Sample data is inserted into these tables.

Uploaded by

Mohana Datla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Create Varchar Varchar Varchar Int

The document contains the SQL code to create three database tables - studies, software, and programmer. The studies table contains student records with their name, institute, course, and course fee. The software table contains records of software developed by programmers with their name, title, development language, cost, development cost, and units sold. The programmer table contains records of programmers with their name, date of birth, date of joining, gender, primary and secondary proficiency. Sample data is inserted into these tables.

Uploaded by

Mohana Datla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CREATE TABLE studies (

PNAME varchar(20),
INSTITUTE varchar(20),
COURSE varchar(20),
COURSE_FEE int
);

insert into studies values


('ANAND','SABHARI','PGDCA',4500),
('ALTAF','COIT','DCA',7200),
('JULIANA','BDPS','MCA',22000),
('KAMALA','PRAGATHI','DCA',5000),
('MARY','SABHARI','PGDCA',4500),
('NELSON','PRAGATHI','DAP',6200),
('PATRICK','PRAGATHI','DCAP',5200),
('QADIR','APPLE','HDCA',14000),
('RAMESH','SABHARI','PGDCA',4500),
('REBECCA','BRILLIANT','DCAP',11000),
('REMITHA','BDPS','DCS',6000),
('REVATHI','SABHARI','DAP',5000),
('VIJAYA','BDPS','DCA',48000);

Create table Software(


PNAME varchar(10),
TITLE varchar(15),i
DEVELOPIN varchar(12),
SCOST decimal(7,2),
DCOST int,
SOLD Int
);

insert into software values


('MARY', 'README', 'CPP', 300.0, 1200, 84),
('ANAND', 'PARACHUTES', 'BASIC', 399.95, 6000, 43),
('ANAND', 'VIDEO TITLING', 'PASCAL', 7500.0, 16000, 9),
('JULIANA', 'INVENTORY', 'COBOL', 3000.0, 3500, 0),
('KAMALA', 'PAYROLL PKG.', 'DBASE', 9000.0, 20000, 7),
('MARY', 'FINANCIAL ACCT.', 'ORACLE', 18000, 85000, 4),
('MARY', 'CODE GENERATOR', 'C', 4500.0, 20000, 23),
('PATTRICK', 'README', 'CPP', 300.0, 1200, 84),
('QADIR', 'BOMBS AWAY', 'ASSEMBLY', 750.0, 3000, 11),
('QADIR', 'VACCINES', 'C', 1900.0, 3100, 21),
('RAMESH', 'HOTEL MGMT.', 'DBASE', 13000, 35000, 4),
('RAMESH', 'DEAD LEE', 'PASCAL', 599.95, 4500, 73),
('REMITHA', 'PC UTILITIES', 'C', 725.0, 5000, 51),
('REMITHA', 'TSR HELP PKG.', 'ASSEMBLY', 2500.0, 6000, 7),
('REVATHI', 'HOSPITAL MGMT.', 'PASCAL', 1100.0, 75000, 2),
('VIJAYA', 'TSR EDITOR', 'C', 900.0, 700, 6);

Create table Programmer(


PNAME varchar(10),
DOB date,
DOJ date,
GENDER char(1),
PROF1 varchar(9),
PROF2 varchar(9),
SALARY Int
);

insert into Programmer values


('ANAND', '12-Apr-66', '21-Apr-92', 'M', 'PASCAL', 'BASIC', 3200),
('ALTAF', '02-Jul-64', '13-Nov-90', 'M', 'CLIPPER', 'COBOL', 2800),
('JULIANA', '31-Jan-60', '21-Apr-90', 'F', 'COBOL', 'DBASE', 3000),
('KAMALA', '30-Oct-68', '02-Jan-92', 'F', 'C', 'DBASE', 2900),
('MARY', '24-Jun-70', '01-Feb-91', 'F', 'CPP', 'ORACLE', 4500),
('NELSON', '11-Sep-85', '11-Oct-89', 'M', 'COBOL', 'DBASE', 2500),
('PATTRICK', '10-Nov-65', '21-Apr-90', 'M', 'PASCAL', 'CLIPPER', 2800),
('QADIR', '31-Aug-65', '21-Apr-91', 'M', 'ASSEMBLY', 'C', 3000),
('RAMESH', '03-May-67', '28-Feb-91', 'M', 'PASCAL', 'DBASE', 3200),
('REBECCA', '01-Jan-67', '01-Dec-90', 'F', 'BASIC', 'COBOL', 2500),
('REMITHA', '19-Apr-70', '20-Apr-93', 'F', 'C', 'ASSEMBLY', 3600),
('REVATHI', '02-Dec-69', '02-Jan-92', 'F', 'PASCAL', 'BASIC', 3700),
('VIJAYA', '14-Dec-65', '02-May-92', 'F', 'FOXPRO', 'C', 3500);

--
=========================================================================================
========================

--Queries
--1)
select avg(scost) from Software where DEVELOPIN = 'PASCAL' group by DEVELOPIN

--2)
select pname , datediff(YY, dob, getdate()) as AGE from Programmer

--3)
select pname, course from studies where COURSE = 'DAP'

--4)
select pname, dob from Programmer where month(dob) = 1

--5)
select max(sold) from software

--6)
select min(course_fee) from studies

--7)
select count(pname) from studies where course = 'PGDCA';

--8)
select title , scost * sold as revenue from software where DEVELOPIN = 'C'

--9)
select title as software from software where pname = 'Ramesh'

--10)
select count(pname) from studies where INSTITUTE = 'Sabhari'

--11)
select * from Software where SCOST*SOLD > 2000

--12)
select * from Software where SCOST*SOLD > DCOST
--13)
select max(scost) from Software where DEVELOPIN = 'C'

--14)
select count(title) from software where DEVELOPIN = 'DBASE'

--15)
select count(pname) from studies where INSTITUTE = 'PRAGATHI'

--16)
select pname, COURSE_FEE from studies where COURSE_FEE between 5000 and 10000

--17)
select avg(COURSE_FEE) from studies

--18)
select * from Programmer where prof1 = 'C' or prof2 = 'C'

--19)
select * from Programmer where prof1 in ('COBOl','PASCAL') or prof2 in ('COBOl','PASCAL')

--20)
select * from Programmer where prof1 not in ('COBOl','PASCAL') and prof2 not in
('COBOl','PASCAL')

--21)
select top 1 pname, datediff(YY, dob, getdate()) as
age from Programmer where gender = 'M' order by age desc

--22)
select avg(datediff(YY, dob, getdate())) from Programmer where gender = 'F'

--23)
select pname, datediff(YY, doj, getdate()) as experince from Programmer order by
experince desc

--24)
select pname, dob from Programmer where MONTH(dob) = month(getdate())

--25)
select count(pname) from Programmer where gender = 'F'

You might also like