Вы находитесь на странице: 1из 5

3.

Perform the following

a. Creating company databases.

b. Viewing all databases.

c. viewing all tables in a databases.

d. creating Tables(with and without constraints).

e. Inserting/updating /deleting records in a table.

f. saving(commit) and undoing(rollback).

Answers
a. create database customer;
b. show databases;
c. select * from tab;

T NAME T ABTY PE CLUST ERID

STUDENT TABLE -

STUDENT11 TABLE -

ENROLLEDIN TABLE -

SUBJECT TABLE -

d. (a) creating Table without and constraints.


create table customer(cust_no number(5),
cust_name varchar(20),
city varchar(20));
Table created.

insert into customer values(101,'neha','bijapur');


insert into customer values(102,'akash','belgaum');
insert into customer values(103,'sneha','hubli');
insert into customer values(104,'mariyam','bangalore');
select * from customer;
CUST_NO CUST_NAME CITY
101 neha bijapur
102 akash belgaum
103 sneha hubli
104 mariyam bangalore
4 rows returned in 0.05 CSV
seconds Export
11141129549203 11143605700225

(b) creating Table with and constraints.

create table employee


( emp_id int UNIQUE,
emp_name varchar(20) NOT NULL,
dept_name varchar(20),
salary number(10,3)CHECK (salary>5000));

Table created.
insert into employee values(10,’anita’,’cs’,9000);
insert into employee values(11,’akash’,’cs’,8000);
insert into employee values(13,’vivek’,’physics’,7000);

select * from employee;


EMP_I D EMP_NAME DEPT _NAME S AL ARY

10 anita cs 9000

13 vivek cs 8000

11 akash physics 7000

insert into employee values(09,'sridhar','chemestry',4000);


ORA-02290: check constraint (AYISHA.SYS_C004050) violated

insert into employee values(09,'','chemestry',4000);

ORA-01400: cannot insert NULL into ("AYISHA"."EMPLOYEE"."EMP_NAME")

(c) creating table with constraints primary key and foreign key

create table customer1(cust_no number(5)primary key,cust_name varchar(20)


NOT NULL,city varchar(20));
Table created

insert into customer1 values(121,'arjun','bangalore');

insert into customer1 values(122,'neha','bijapur');

insert into customer1 values(123,'sneha','mysore');

insert into customer1 values(124,'shaheed','bangalore');

insert into customer1 values(125,'arman','hubli');

select * from customer1;

CUST _NO CUST _NAME CITY

121 arjun bangalore

122 neha bijapur

123 sneha mysore

124 shaheed bangalore

125 arman hubli

(d). creating table with constraints primary key and foreign key

create table orders(orderno number(5) primary key,O_date date,cust_no


number(5),ord_amt number(10,4),foreign key(cust_no)references
customer1(cust_no));

insert into orders values(1201,'11-july-2019',123,15000);

insert into orders values(1202,'11-july-2019',124,15000);

insert into orders values(1203,'11-july-2019',111,15000);

ORA-02291: integrity constraint (AYISHA.SYS_C004055) violated - parent key not


found

insert into orders values(1203,'15-june-2018',125,9000);

select * from orders;


ORDERNO O_DAT E CUST _NO ORD_AMT
1201 11-JUL-19 123 15000
1202 11-JUL-19 124 15000
1203 15-JUN-18 125 9000

e. updating /deleting records in a table.


delete from customer1 where cust_name='neha';
1 row deleted
select * from customer1;
CUST _NO CUST _NAME CITY
121 arjun bangalore
123 sneha mysore
124 shaheed bangalore
125 arman hubli

delete from orders where ord_amt=9000;


1 row(s) deleted.
ORDERNO O_DAT E CUST _NO ORD_AMT
1201 11-JUL-19 123 15000
1202 11-JUL-19 124 15000

select * from employee;


EMP_I D EMP_NAME DEPT _NAME S AL ARY
10 anita cs 9000
13 vivek cs 8000
11 akash physics 7000

update employee

set salary=25000

where emp_id=10;
1 row(s) updated.

select * from employee;


EMP_I D EMP_NAME DEPT _NAME S AL ARY
10 anita cs 25000
13 vivek cs 8000
11 akash physics 7000
f. saving(commit) and undoing(rollback).

See the manual and write the information only

Вам также может понравиться