Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
224 views

SQL

The document contains SQL commands to create tables, sequences, insert and update data, add/drop constraints and columns. It creates tables for members, books and book issues with various data types and constraints. It inserts sample data, updates and deletes rows, commits and rolls back transactions, and drops and alters tables, sequences and constraints.

Uploaded by

Sale Her Mumbai
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
224 views

SQL

The document contains SQL commands to create tables, sequences, insert and update data, add/drop constraints and columns. It creates tables for members, books and book issues with various data types and constraints. It inserts sample data, updates and deletes rows, commits and rolls back transactions, and drops and alters tables, sequences and constraints.

Uploaded by

Sale Her Mumbai
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q. no.

1
create table Member(
member_id number(5),
member_name varchar2(20),
member_address varchar2(50),
acc_open_date date,
membership_type varchar2(20),
fees_paid number(4),
max_books_allowed number(2),
penalty_amount number(7,2));
create table books
(book_no number(6),
book_name varchar2(30),
author_name varchar2(30),
cost number(7,2),
category char(10));

create table issue( lib_issue_id number(10),


book_no number(6),
member_id number(5),
issue_date date,return_date date);
Q. no.2
desc member;
desc issue;
desc books;
Q.No.3
drop table member;
Q.No.4
SQL> create table member1(
member_id number(5) constraint member1_id_pk primary key,
member_name varchar2(30),
member_address varchar2(50),
acc_open_date date,
membership_type varchar2(20)
check (membership_type ='Lifetime' or membership_type = 'Annual' or membersh
ip_type = 'Half Yearly' or membership_type= 'Quarterly'),
fees_paid number(4),
max_books_allowed number(2),
penalty_amount number(7,2));
Q.No.5
alter table member modify (member_name varchar2(30));
Q.No.6
alter table issue add reference char(30);
Q.No.7
alter table issue drop column reference;
Q.No.8
rename issue to lib_issue;
Q.No.9
insert into member values(1,'Richa Sharma','Pune','10-dec-05','Lifetime',2500,5,
50);
insert into member values(2,'Garma Sen','Pune',sysdate,'Annual',1000,3,null);
Q.No.10
insert into member values(3,'Manasi K','Pune',sysdate,'Annual',1000,2,null);
insert into member values(4,'Priyanka C','Mumbai','04-dec-1990','Quarterly',1000
,3,12);
insert into member values(5,'Madhuri A','Pune','03-oct-2010','Annual',1000,1,nul
l);
insert into member values(6,'Abha Khanna','Mumbai','01-sep-2001','Half Yearly',1
000,3,11);
insert into member values(7,'Mitali P','Pune',sysdate,'Annual',1000,null,10);
Q no.11
Not posssible as modifications are done from lower to higher level of variable s
ize.
Q.No.12
SQL> insert into member values(8,'Jinal P','Pune',sysdate,'Annual',1000,110,10);
insert into member values(8,'Jinal P','Pune',sysdate,'Annual',1000,110,10)
*
ERROR at line 1:
ORA-01438: value larger than specified precision allows for this column
Since the variable size is 2.
Q,No.13
create table member101 as select * from member;
Q.No.14
alter table member1 add constraint member_books_penalty check(max_books_allowed
< 100 and penalty_amount <= 1000);

Q.No.15
drop table books;
Q.No.16
create table books_copy
(book_no number(6) constraint books_no_pk primary key,
book_name varchar2(30) not null,
author_name varchar2(30),
cost number(7,2),
category char(10) check(category = 'Science' or category='Fiction' or category=
'Database' or category='RDBMS' or category='others'));
Qno.17-18
SQL> insert into books_copy values(&book_no,&book_name,&author_name,&cost,&categ
ory);
Enter value for book_no: 101
Enter value for book_name: 'Harry Potter'
Enter value for author_name: 'Rowling'
Enter value for cost: 500
Enter value for category: 'Fiction'
old 1: insert into books_copy values(&book_no,&book_name,&author_name,&cost,&c
ategory)
new 1: insert into books_copy values(101,'Harry Potter','Rowling',500,'Fiction
')
1 row created.
SQL> insert into books_copy values(&book_no,&book_name,&author_name,&cost,&categ
ory);
Enter value for book_no: 102
Enter value for book_name: 'Twilight'
Enter value for author_name: 'Stephenie Meyer'
Enter value for cost: 800
Enter value for category: 'Science'
old 1: insert into books_copy values(&book_no,&book_name,&author_name,&cost,&c
ategory)
new 1: insert into books_copy values(102,'Twilight','Stephenie Meyer',800,'Sci
ence')
1 row created.
Q.No.19
create table books101
(book_no number(6) constraint books101_no_pk primary key,
book_name varchar2(30) not null,
author_name varchar2(30),
cost number(7,2),
category char(10) check(category = 'Science' or category='Fiction' or category=
'Database' or category='RDBMS' or category='others'));
Q.No.20
insert into books101 (select * from books_copy);
Q.No.21
commit;
Q.No.22
select * from books101;
Q.No.23
insert into books_copy values(105, 'National Geographic', 'Adis Scott', 1000,
'Science');
Q.No.24
rollback;
Q.No.25
update books_copy set category='RDBMS',cost=300 where book_no=103;
Q.No.26
rename lib_issue to issue;
Q.No.27
drop table issue;
Q.No.28
create table issue_copy( lib_issue_id number(10) constraint issue_id_pk primary
key,
book_no number(6) references books_copy(book_no),
member_id number(5) references member1(member_id),
issue_date date check(issue_date <= '01-Jan-2009'),
return_date date,
check(issue_date<return_date)
);
In above example we can't process with system date or any system function in che
ck constraint
Q.No.29
insert into issue values(7001,101,1,'10-Dec-06',null);
insert into issue values(7002,102,2,'25-Dec-06',null);
insert into issue values(7003,104,1,'15-Jan-06','21-jan-06');
insert into issue values(7004,101,1,'04-Jul-06',null);
insert into issue values(7005,104,2,'15-Nov-06','26-nov-06');
insert into issue values(7006,101,3,'18-Feb-06',null);
Q.No.30
savepoint a29;
Q.No.31
alter table issue_copy disable constraint issue_id_pk;
Q.No.32
SQL> insert into issue_copy values(7007,101,21,'18-Feb-06',null);
insert into issue_copy values(7007,101,21,'18-Feb-06',null)
*
ERROR at line 1:
ORA-02291: integrity constraint (CS_2.SYS_C0013125) violated - parent key not
found
Q.No.35
It will delete the corresponding child records in other table i.e issue table
Q.no.36
update issue set return_date=issue_date+15 where lib_issue_id=7004;
update issue set return_date=issue_date+15 where lib_issue_id=7005;
Q.No.37
update member1 set penalty_amount=100 where member_name='Garma Sen';
Q.No.38
savepoint x;
Q.No.41
rollback to savepoint x;
Q.No.42
savepoint b;
Q.No.43
drop table member101;
Q.NO.44
drop table books101;
Q.No.45
desc member
desc books
desc issue
select * from member;
select * from books;
select * from issue;
Q.No.46
create sequence no_seq
start with 100
increment by 2
maxvalue 200
NOCYCLE
NOCACHE;
Q.No.47
drop sequence no_seq;
Q.No.48
create sequence book_seq
start with 101
increment by 1
maxvalue 1000
NOCYCLE
NOCACHE;
Q.No.49
create sequence member_seq
start with 1
increment by 1
maxvalue 100
NOCYCLE
NOCACHE;

Q.No.50
drop sequence book_seq;
drop sequence member_seq;

You might also like