0% found this document useful (0 votes)
16 views5 pages

Group1 AlterQuery

Uploaded by

Sarthak Mittal
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)
16 views5 pages

Group1 AlterQuery

Uploaded by

Sarthak Mittal
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
You are on page 1/ 5

1.

Create 2 tables:
Doctor - Did int, Dname varchar2(20), Specialization varchar2(5), Salary int
Sufferer - Pid int, Pname varchar2(20), Age int, sex varchar2(5), DOB date, DO_Admission
Date, Disease varchar2(15), Did int
2. Change the name of table 2 from Sufferer to Patient.
3. Change the varchar size of specialization from 5 to 20.
4. Add two columns in Doctor table named as Mentor_Doctor_Id varchar2(5) and Shift
varcha2(10).
5. Change the datatype of Mentor_Doctor_Id from varcha2(5) to integer.
6. Change the constraints of Sex and Age in Patient table as not null.
7. Insert all the values in both the tables (same as given below)

DID DNAME SPECIALIZATION SALARY MENTOR_DOCTOR_ID SHIFT

1 Simran Kumari Cardiology 150000 1010 Morning

2 Muskan Aggarwal Dermatology 135000 1020 Evening

3 Devanshi Narang Pediatrics 125000 1030 Morning

4 Aasees Kaur Psychiatry 115000 1040 Evening

PID PNAME AGE SEX DOB DO_ADMISS DISEASE DID


101 Amit Kumar 23 M 04-MAY-99 06-JUL-22 Pneumonia 3

202 Binayak Chand 80 M 09-OCT-42 10-JAN-22 Stroke 1

303 Diana Ellie 12 F 03-APR-10 05-JUN-22 High Fever 4


404 Rashmi Tondon 34 F 15-MAY-88 26-OCT-22 Stroke 1

505 Manish Jonny 78 M 09-APR-44 01-NOV-22 Bipolar 4

606 Ursula Singh 23 F 14-NOV-99 01-MAR-22 Acne 2


707 Jack Sparrow 4 M 14-NOV-18 25-JAN-22 High Fever 3

808 Esha Sharma 67 F 08-FEB-55 19-JAN-22 Bipolar 4

909 Shaan Mehta 32 M 30-MAR-55 28-AUG-22 Heart Attack 1

8. Make Did in Doctor table and Pid in Patient table as Primary Keys.
9. Make Did in Patient table as foreign keys in reference with Did in Doctor table.
10. Delete the Shifts column from the Doctor table.
Answers
1. create table Doctor (Did int, Dname varchar2(10), Specialization varchar2(5), Salary int);
create table Sufferer (Pid int, Pname varchar2(20), Age int, sex varchar2(5), DOB date,
DO_Admission Date, Disease varchar2(15), Did int);
2. alter table Sufferer rename to Patient;
3. alter table Doctor modify specialization varchar2(20
4. alter table Doctor add Mentor_Doctor_id varchar2(5);
alter table Doctor add Shift varchar2(10);
5. alter table Doctor modify Mentor_Doctor_id int;
6. alter table Patient modify Age int NOT NULL;
alter table Patient modify Sex Varchar2(5) NOT NULL;
7. Insert into Doctor values (1, 'Simran Kumari', 'Cardiology', 150000, 1010, 'Morning');
Insert into Doctor values (2, 'Muskan Aggarwal', 'Dermatology', 135000, 1020, 'Evening');
Insert into Doctor values (3, 'Devanshi Narang', 'Pediatrics', 125000, 1030, 'Morning');
Insert into Doctor values (4, 'Aasees Kaur', 'Psychiatry', 115000, 1040, 'Evening');
Insert into Patient values (101, 'Amit Kumar', 23, 'M', '4-May-1999', '6-July-2022',
'Pneumonia', 3);
Insert into Patient values (202, 'Binayak Chand', 80, 'M', '9-Oct-1942', '10-Jan-2022',
'Stroke', 1);
Insert into Patient values (303, 'Diana Ellie', 12, 'F', '3-April-2010', '5-June-2022', 'High
Fever', 4);
Insert into Patient values (404, 'Rashmi Tondon', 34, 'F', '15-May-1988', '26-Oct-2022',
'Stroke', 1);
Insert into Patient values (505, 'Manish Jonny', 78, 'M', '9-April-1944', '01-Nov-2022',
'Bipolar', 4);
Insert into Patient values (606, 'Ursula Singh', 23, 'F', '14-Nov-1944', '01-March-2022',
'Acne', 2);
Insert into Patient values (606, 'Ursula Singh', 23, 'F', '14-Nov-1999', '01-March-2022',
'Acne', 2);
Insert into Patient values (707, 'Jack Sparrow', 4, 'M', '14-Nov-2018', '25-Jan-2022', 'High
Fever', 3);
Insert into Patient values (808, 'Esha Sharma', 67, 'F', '8-Feb-1955', '19-Jan-2022',
'Bipolar', 4);
Insert into Patient values (909, 'Shaan Mehta', 32, 'M', '30-March-1955', '28-Aug-2022',
'Heart Attack', 1);
8. alter table Doctor add primary key (Did);
alter table Patient add primary key (Pid);
9. alter table Patient add foreign key (Did) references Doctor (Did);
10. alter table Doctor drop column shift;

SQL> create table Doctor (Did int, Dname varchar2(10), Specialization varchar2(5), Salary int);

Table created.
SQL> create table Sufferer (Pid int, Pname varchar2(20), Age int, sex varchar2(5), DOB date,
DO_Admission Date, Disease varchar2(15), Did int);

Table created.

SQL> alter table Sufferer rename to Patient;

Table altered.

SQL> alter table Doctor modify specialization varchar2(20);

Table altered.

SQL> alter table Doctor add Mentor_Doctor_id varchar2(5);

Table altered.

SQL> alter table Doctor modify Mentor_Doctor_id int;

Table altered.

SQL> commit;

Commit complete.

SQL> desc Doctor;


Name Null? Type
----------------------------------------- -------- ----------------------------
DID NUMBER(38)
DNAME VARCHAR2(10)
SPECIALIZATION VARCHAR2(20)
SALARY NUMBER(38)
MENTOR_DOCTOR_ID NUMBER(38)

SQL> desc Patient;


Name Null? Type
----------------------------------------- -------- ----------------------------
PID NUMBER(38)
PNAME VARCHAR2(20)
AGE NUMBER(38)
SEX VARCHAR2(5)
DOB DATE
DO_ADMISSION DATE
DISEASE VARCHAR2(15)
DID NUMBER(38)

SQL> alter table Doctor add Shift varchar2(10);


Table altered.

SQL> alter table Patient modify Age int NOT NULL;

Table altered.

SQL> alter table Patient modify Sex Varchar2(5) NOT NULL;

Table altered.

1 row created.
SQL> insert into Patient values (101, 'Amit Kumar', 23, 'M', '4-May-1999', '6-July-2022',
'Pneumonia', 3);

1 row created.

SQL> insert into Patient values (202, 'Binayak Chand', 80, 'M', '9-Oct-1942', '10-Jan-2022',
'Stroke', 1);

1 row created.

SQL> insert into Patient values (303, 'Diana Ellie', 12, 'F', '3-April-2010', '5-June-2022', 'High
Fever', 4);

1 row created.

SQL> insert into Patient values (404, 'Rashmi Tondon', 34, 'F', '15-May-1988', '26-Oct-2022',
'Stroke', 1);

1 row created.

SQL> insert into Patient values (505, 'Manish Jonny', 78, 'M', '9-April-1944', '01-Nov-2022',
'Bipolar', 4);

1 row created.

SQL> insert into Patient values (606, 'Ursula Singh', 23, 'F', '14-Nov-1944', '01-March-2022',
'Acne', 2);

1 row created.

SQL> insert into Patient values (606, 'Ursula Singh', 23, 'F', '14-Nov-1999', '01-March-2022',
'Acne', 2);

1 row created.
SQL> insert into Patient values (707, 'Jack Sparrow', 4, 'M', '14-Nov-2018', '25-Jan-2022', 'High
Fever', 3);

1 row created.
SQL> insert into Patient values (808, 'Esha Sharma', 67, 'F', '8-Feb-1955', '19-Jan-2022', 'Bipolar',
4);

1 row created.

SQL> insert into Patient values (909, 'Shaan Mehta', 32, 'M', '30-March-1955', '28-Aug-2022',
'Heart Attack', 1);

1 row created.

SQL> alter table Doctor add primary key (Did);

Table altered.

SQL> alter table Patient add primary key (Pid);

Table altered.
SQL> alter table Patient add foreign key (Did) references Doctor (Did);

Table altered.
SQL> alter table Doctor drop column shift;

Table altered.

You might also like