Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
93 views

SQL Questions

The document describes an entity-relationship diagram showing the relationships between raw material suppliers, pharmaceutical companies, pharmacies, and customers. It includes the structure of tables to represent these entities and relationships in a database, as well as sample data and queries on the tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

SQL Questions

The document describes an entity-relationship diagram showing the relationships between raw material suppliers, pharmaceutical companies, pharmacies, and customers. It includes the structure of tables to represent these entities and relationships in a database, as well as sample data and queries on the tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

ENTITY-RELATIONSHIP DIAGRAM

Registration
Name Registration
no.
s no. Name
s

Raw Material Buys Pharmaceutical Company


Supplier From

Email Email Address


Address

Buys
From
11

Sex Quantit
yl Med_Nam
Price e
Patient or Buys Pharmacy
Customer From

P_Name P_Registratio
Name n No.
Pa_id P_Ema P_addres
il s
Here we have all the entities have many to many relationships. The reason behind
it is, patient never goes to a single pharmacy for his/her required drugs in life span.
Again pharmacy never depends on a single pharmaceutical company for its supply
of drugs. Same thing happens for pharmaceutical company and raw material
supplier.

SQL> create table rm_sup

2 ( R_registratn_no varchar2(10) primary key,

3 Name char(20) not null,

4 Email varchar2(20),

5 Address varchar2(20) not null);

Table created.

SQL> create table customer

2( Pa_id varchar2(10) primary key,

3 Name char(20) not null,

4 Sex char(5));

Table created.

SQL> create table pharma_co

2( Pc_registratn_no varchar2(10) primary key,

3 R_registratn_no varchar2(10) references rm_sup(R_registratn_no),

4 Name char(20) not null,

5 Email varchar2(20),

6 Address varchar2(20) not null);


Table created.

SQL> create table pharma

2( P_registratn_no varchar2(10) primary key,

3 Pc_registratn_no varchar2(10) references pharma_co(Pc_registratn_no),

4 Pa_id varchar2(10) references customer(Pa_id),

5 P_name char(20) not null,

6 P_email varchar2(20),

7 P_add varchar2(20) not null,

8 Med_name varchar2(10) not null,

9 Price number(10,2) not null,

10 Qty varchar2(10) not null);

Table created.
STRUCTURE OF TABLES

TABLE: RAW MATERIAL SUPPLIER

FIELD NAME DATA TYPE CONSTRAINTS


R_registratn_no Varchar2 Primary key
Name char Not null
Email Varchar2
Address Varchar2 Not null

TABLE: CUSTOMER

FIELD NAME DATA TYPE CONSTRAINTS


Pa_id Varchar2 Primary key
Name char Not null
Sex char
TABLE: PHARMACEUTICAL COMPANY

FIELD NAME DATA TYPE CONSTRAINTS


Pc_registratn_no Varchar2 Primary key
R_registratn_no Varchar2
Name char Not null
Email Varchar2
Address Varchar2 Not null

TABLE: PHARMACY

FIELD NAME DATA TYPE CONSTRAINTS


P_registratn_no Varchar2 Primary key
Pc_registratn_no Varchar2
Pa_id varchar2 Varchar2
P_name char Not null
P_email Varchar2
P_add Varchar2 Not null
Med_name Varchar2 Not null
Price number Not null
Qty Varchar2 Not null

SQL> insert into rm_sup values('rm1012','rameshsupplrs','ramesh@gmail.com','sd-


30,rohini,delhi');

1 row created.

SQL> insert into rm_sup values('rm1018','reetasupplrs','reeta@gmail.com','pd-


04,pitampura,delhi');

1 row created.

SQL> insert into rm_sup


values('rm1014','maheshsupplrs','mahesh@gmail.com','pd-16,tnagar,delhi');

1 row created.

SQL> insert into rm_sup values('rm1016','seemaasupplrs','seemaa@gmail.com','ru-


19,rohini,delhi');

1 row created.

SQL> insert into pharma_co


values('pc1024','rm1014','abcompny','ab@gmail.com','ab-2,lnagar,delhi');

1 row created.
SQL> insert into pharma_co
values('pc1026','rm1016','cdcompny','cd@gmail.com','cd-4,jnagar,delhi');

1 row created.

SQL> insert into pharma_co


values('pc1028','rm1018','decompny','de@gmail.com','de-6,hnagar,delhi');

1 row created.

SQL> insert into pharma_co


values('pc1022','rm1012','adcompny','ad@gmail.com','ad-2,gnagar,delhi');

1 row created.

SQL> insert into customer values('cu1034','sohan','male');

1 row created.

SQL> insert into customer values('cu1032','mohan','male');

1 row created.

SQL> insert into customer values('cu1036','seeta','female');

1 row created.

SQL> insert into customer values('cu1038','geeta','null');


1 row created.

SQL> insert into pharma


values('ph1002','pc1022','cu1032','efpharmacy','ef@gmail.com','ef-
5,tnagar,delhi','combiflame','20','550');

1 row created.

SQL> insert into pharma


values('ph1004','pc1022','cu1036','etpharmacy','et@gmail.com','ed-
5,rnagar,delhi','aspirin','10','400');

1 row created.

SQL> insert into pharma


values('ph1006','pc1024','cu1038','fgpharmacy','fg@gmail.com','eg-
7,ppnagar,delhi','crocin','25','800');

1 row created.

SQL> insert into pharma


values('ph1008','pc1024','cu1038','ghpharmacy','ef@gmail.com','eh-
5,vnagar,delhi','aspirin','15','950');

1 row created.

SQL> select * from rm_sup;


R_REGISTRA NAME EMAIL ADDRESS

---------- -------------------- -------------------- --------------------

rm1012 rameshsupplrs ramesh@gmail.com sd-30,rohini,delhi

rm1018 reetasupplrs reeta@gmail.com pd-04,pitampura,delhi

rm1014 maheshsupplrs mahesh@gmail.com pd-16,tnagar,delhi

rm1016 seemaasupplrs seemaa@gmail.com ru-19,rohini,delhi

SQL> select * from customer;

PA_ID NAME SEX

---------- -------------------- -----

cu1032 mohan male

cu1034 sohan male

cu1036 seeta female

cu1038 geeta null

SQL> select * from pharma_co;

PC_REGISTR R_REGISTRA NAME EMAIL ADDRESS


---------- ---------- -------------------- -------------------- --------------------

pc1024 rm1014 abcompny ab@gmail.com ab-2,lnagar,delhi

pc1026 rm1016 cdcompny cd@gmail.com cd-4,jnagar,delhi

pc1028 rm1018 decompny de@gmail.com de-6,hnagar,delhi

pc1022 rm1012 adcompny ad@gmail.com ad-2,gnagar,delhi

SQL> select * from pharma;

P_REGISTRA PC_REGISTR PA_ID P_NAME P_EMAIL


P_ADD MED_NAME PRICE QTY

---------- ---------- ---------- -------------------- -------------------- --------------------


---------- ---------- ----------

ph1002 pc1022 cu1032 efpharmacy ef@gmail.com ef-


5,tnagar,delhi combiflame 20 550

ph1004 pc1022 cu1036 etpharmacy et@gmail.com ed-


5,rnagar,delhi aspirin 10 400

ph1006 pc1024 cu1038 fgpharmacy fg@gmail.com eg-


7,ppnagar,delhi crocin 25 800

ph1008 pc1024 cu1038 ghpharmacy ef@gmail.com eh-


5,vnagar,delhi aspirin 15 950
Queries

Q1. Display the names of all the raw material suppliers who lives in rohini

SQL> select name from rm_sup where address like%rohini%;

NAME

--------------------

rameshsuppliers

seemasuppliers

Q2. Display the names of customers who havnt mentioned their sex

SQL> select name from customer where sex=null;

NAME

--------------------

geeta

Q3. Display names of customers having transactions from the fgpharmacy

SQL> select name from customer,pharma where customer.pa_id and


p_name=fgpharmacy;

NAME
--------------------

geeta

Q4. Display the address of the raw material supplier with registration no. rm 1016

SQL> select address from rm_sup where R_registratn_no=rm1016;

ADDRESS

--------------------

Ru-19,rohini,delhi

Q5.Display the name and registration no of pharmacies having quantity of


aspirin>500

SQL> select p_name,p_registratn_no from pharma where med_name=aspirin and


qty>500;

P_NAME P_REGISTRA

-------------------- ----------

ghpharmacy ph1008

Q6 Register sex of geeta in customer table as female

SQL> update customer set sex =female where name=geeta;

1 row updated.

Q7. Delete a record from pharmacy table where registeration no is ph1002


SQL> delete from pharma where P_registratn_no=ph1002;

1 row deleted.

Q8. Select pa_id from customer table where name is mohan

SQL> select pa_id from customer where name=mohan;

PA_ID

----------

cu1032

Q9. Increase the width of address column to 30 in pharmacy table

SQL> alter table pharma modify(p_add varchar2(30));

Table altered.

Q10. Drop table pharmacy

SQL> drop table pharma;

Table dropped

You might also like