0% found this document useful (0 votes)
15 views4 pages

Product and Salesman Database Queries

The document outlines SQL commands for creating and manipulating various database tables, including 'product', 'student', 'exam', 'doctor', 'employee', 'division', 'member', 'salesman', and 'customer'. It includes commands for creating tables, inserting data, updating records, and querying information based on specific criteria. Additionally, it demonstrates the use of aggregate functions and joins to retrieve and analyze data from multiple tables.

Uploaded by

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

Product and Salesman Database Queries

The document outlines SQL commands for creating and manipulating various database tables, including 'product', 'student', 'exam', 'doctor', 'employee', 'division', 'member', 'salesman', and 'customer'. It includes commands for creating tables, inserting data, updating records, and querying information based on specific criteria. Additionally, it demonstrates the use of aggregate functions and joins to retrieve and analyze data from multiple tables.

Uploaded by

Aneri Patel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. i.

create table product(PCode varchar(10) primary key,PName varchar(50),UPrice


int,Manufacturer varchar(30));

insert into product values('P01','Washing Powder',120,'Surf'),

-> ('P02','Tooth Paste',54,'Colgate'),

-> ('P03','Soap',25,'Lux'),

-> ('P04','Tooth Paste',65,'Pepsodant'),

-> ('P05','Soap',38,'Dove'),

-> ('P06','Shampoo',245,'Dove');

iii. select pname,uprice,pcode from product order by pname desc;

select pname,uprice,pcode from product order by uprice;

iv. alter table product add discount int;

v. update product set discount=uprice*10/100 where uprice>100;

update product set discount=0 where uprice<100;

vi. update product set uprice=uprice+uprice*12/100 where manufacturer='dove';

vii. select count(pname) as total_no_of_products_by_each_manufacturer,manufacturer from


product group by manufacturer;

2. a. create database streams_of_students;

d. update student set stcode='S03' WHERE NAME='JAY';

E. SELECT NAME FROM STUDENT WHERE NAME LIKE '%A' ORDER BY NAME;

F. select [Link] from student s,stream st where [Link] in ('Science','Humanities') and


[Link]=[Link] order by [Link];

select [Link] from student s,stream st where [Link] in ('Science','Humanities') and


[Link]=[Link] order by [Link];

G. SELECT COUNT([Link]),[Link] FROM STUDENT S,STREAM ST WHERE


[Link]=[Link] GROUP BY [Link] HAVING COUNT([Link])>1;

H. SELECT NAME FROM STUDENT ORDER BY ADMNO DESC;


J. ALTER TABLE STREAM ADD TEACHERINCHARGE VARCHAR(30);

k. select [Link],[Link] from stream ST,student S where [Link]=[Link];

3.

i. select * from exam where stream='humanities' order by percentage desc;

ii. select adno,sname,percentage,stream from exam where length(sname)<6;

III. ALTER TABLE ADD BUSFEES DECIMAL(8,2);

iV. update exam set percentage=percentage+percentage*2/100 where stream='humanities';

4.

i. SELECT NAME FROM EXAM WHERE DIVISION='FIRST' ORDER BY NAME;

II. SELECT NAME,SUBJECT,STIPEND AS ANNUALSTIPEND FROM EXAM;

III. SELECT COUNT(*) AS NO_OF_STUDENTS FROM EXAM WHERE SUBJECT='ACCOUNTS' OR


SUBJECT='INFORMATICS';

5.

I. SELECT * FROM DOCTOR WHERE EXPERIENCE>5 ORDER BY DNAME;

II. UPDATE DOCTOR SET SALARY=SALARY+SALARY*15/100 WHERE EXPERIENCE>8;

III. SELECT DNAME FROM DOCTOR WHERE DNAME LIKE '%H';

IV. SELECT DISTINCT(CITY) FROM DOCTOR;

V. SELECT DNAME FROM DOCTOR WHERE CITY='JAIPUR' OR CITY='TONK';

VI. ALTER TABLE DOCTOR ADD ADHARNO INT;

VII. SELECT * FROM DOCTOR ORDER BY SALARY DESC;

6.

I. SELECT [Link],[Link],[Link],[Link] FROM EMPLOYEE E,JOB J WHERE


[Link]=[Link];

II. SELECT [Link],[Link],[Link] FROM EMPLOYEE E,JOB J WHERE [Link]>1300000 AND


[Link]=[Link];

III. SELECT [Link],[Link] FROM EMPLOYEE E,JOB J WHERE [Link] LIKE '%SINGH%' AND
[Link]=[Link];
IV. UPDATE EMPLOYEE SET JOBID=104 WHERE EMPLOYEEID='E4';

7. create table division(Divno int primary key,Divname varchar(30),Location varchar(20));

create table member(EmpId int primary key,Name varchar(30),Pay int,Divno int,foreign key(divno)
references division(divno) on delete cascade on update cascade);

i. select [Link],[Link] from member m,division d where [Link]=[Link];


ii. select [Link],[Link] from member m,division d where [Link]=[Link];
iii. SELECT DISTINCT([Link]) FROM MEMBER M,DIVISION D WHERE [Link]=[Link];
iv. select divno from member;
v. select divno from division;
vi. Select [Link] from member m,division d where [Link]=[Link];

8. create table salesman(salesman_id int primary key,name varchar(30),city varchar(40),commission


int);

create table customer(customer_id int primary key,cust_name varchar(40),city varchar(40),grade


int,salesman_id int,foreign key(salesman_id) references salesman(salesman_id) on delete cascade on
update cascade);

insert into salesman values(1001,'Muktar','Chennai',20),

-> (1002,'Surya','Jammu',13),

-> (1003,'Karish','Chennai',21),

-> (1004,'Sunish','Delhi',10),

-> (1005,'Ajay','Jammu',15);

insert into customer values(10,'Mona','Jammu',200,1005),

-> (20,'Vijay','Delhi',150,1004),

-> (30,'April','Delhi',230,1004),

-> (40,'Misha','Chennai',120,1003),

-> (50,'Aarav','Chennai',210,1001);

i. select c.cust_name,[Link] from salesman s,customer c where c.salesman_id=s.salesman_id and


[Link]=’Chennai’ and [Link]=’chennai’;

ii. select distinct(name),city from salesman;

iii. select [Link] from salesman s,customer c where s.salesman_id=c.salesman_id and [Link]!='Delhi' and
[Link]!='Jammu';
iv. select [Link] from salesman s,customer c where s.salesman_id=c.salesman_id and [Link]>=200;

v. select [Link] from salesman s,customer c where s.salesman_id=c.salesman_id and [Link]=200 and
[Link]='Jammu';

vi. select c.cust_name from customer c,salesman s where [Link]>=15 and


s.salesman_id=c.salesman_id;

Common questions

Powered by AI

Adding a discount attribute to the product table, as done through `ALTER TABLE product ADD discount INT` , is significant because it allows the business to dynamically manage and display promotional offers. It enables targeted pricing strategies, such as providing a 10% discount on products priced over 100, as set with `UPDATE product SET discount=uprice*10/100 WHERE uprice>100` . This capability can enhance customer engagement by increasing perceived value through visible discounts and potentially boosting sales by incentivizing purchases.

Student data integrity is maintained when altering student codes by issuing direct updates with precise conditions, such as `UPDATE student SET stcode='S03' WHERE NAME='JAY'` . This specific alteration reduces ambiguity and minimizes the chance of erroneous changes. However, regularly altering identifiers like student codes might require additional checks to ensure that all related records maintain referential integrity, especially if linked to other tables in a database via foreign keys.

The introduction of new attributes, such as `discount` in the product table and `ADHARNO` in the doctor table, significantly broadens analytical possibilities. With `ALTER TABLE product ADD discount INT` , financial analyses incorporating discount data become feasible, providing deeper insights into profitability and customer pricing strategies. Similarly, the addition of `ADHARNO` through `ALTER TABLE DOCTOR ADD ADHARNO INT` permits the tracking of demographic data tied to each medical practitioner, enabling comprehensive records management and demographic analyses. These attributes enrich data profiles, facilitating multidimensional evaluations and informed decision-making.

Searches within the product table are optimized using attribute-based sorting and filtering. Queries such as `SELECT pname, uprice, pcode FROM product ORDER BY pname DESC` and `SELECT pname, uprice, pcode FROM product ORDER BY uprice` are employed to facilitate quick retrieval based on descending order of product names or ascending order of prices, respectively. This sorting accelerates finding relevant records and enhances database performance by limiting the data scope presented to users, aligning data access with specific user criteria.

The database systems analyze and report educational and salary metrics through complex SQL queries. For instance, educational attainment is evaluated using queries like `SELECT COUNT(S.NAME),ST.STREAM FROM STUDENT S,STREAM ST WHERE S.STCODE=ST.STCODE GROUP BY ST.STREAM HAVING COUNT(S.NAME)>1` , which aggregates student numbers by their stream. Meanwhile, salary metrics are reviewed with detailed breakdowns as seen in `SELECT * FROM DOCTOR WHERE EXPERIENCE>5 ORDER BY DNAME` and salary updates through `UPDATE DOCTOR SET SALARY=SALARY+SALARY*15/100 WHERE EXPERIENCE>8` . These commands use aggregation, filtering, and arithmetic operations to provide nuanced insights into educational distributions and compensation structures.

The database schema permits selective updating of product prices based on manufacturer. Specifically, for products manufactured by 'Dove', the update statement increases their price by 12% through the following SQL command: `UPDATE product SET uprice=uprice+uprice*12/100 WHERE manufacturer='dove'` . This targeted update allows for dynamic pricing strategies based on specific criteria, leading to potential price differentials across products depending on their manufacturer.

High-performance teams are strategically structured by organizing personnel into divisions with clear lines of hierarchical dependency, as indicated by the relationships between the division and member tables. The tables employ a foreign key constraint, `FOREIGN KEY(divno) REFERENCES division(divno) ON DELETE CASCADE ON UPDATE CASCADE` , to ensure integrative management across divisions. This ensures that changes or updates are seamlessly propagated within the organizational units, maintaining uniformity and coordination. The `SELECT m.name,d.divname FROM member m,division d WHERE d.divno=m.divno` query further enables quick identification and analysis of team compositions, aiding the strategic evaluation of team structures.

The SQL commands reveal that each salesman is associated with customers based in specific cities, implying geo-targeted sales strategies. For instance, salesmen based in Chennai and linked to customers also in Chennai are retrieved via `SELECT c.cust_name, s.name FROM salesman s, customer c WHERE c.salesman_id = s.salesman_id AND s.city='Chennai' AND c.city='chennai'` . Additionally, analysis of salesmen associated with customers of specific grades reflects tiered marketing strategies, with commands like `SELECT s.name FROM salesman s, customer c WHERE s.salesman_id = c.salesman_id AND c.grade >= 200` . This shows strategic mapping of sales staff to market segments based on criteria such as regional presence and customer purchase potential.

Insights into sales commission and performance are extracted using linkages between the salesperson and customer tables. For example, retrieving customers linked to sales staff with higher commission is facilitated by `SELECT c.cust_name FROM customer c, salesman s WHERE s.commission>=15 and s.salesman_id=c.salesman_id` , suggesting a correlation between high commission and the salespersons' performance. Such insights can guide businesses in forming compensation strategies that reward more effective salespersons, thereby enhancing overall enterprise performance.

Cascading plays a crucial role in maintaining relational integrity between the division and member tables by ensuring that changes in a parent record are propagated to related child records. This is seen in the member table where `FOREIGN KEY(divno) REFERENCES division(divno) ON DELETE CASCADE ON UPDATE CASCADE` is defined. Such constraints ensure that any deletion or update of division records automatically reflects across dependent member records, preventing orphaned data and maintaining synchronized relationships.

You might also like