Oracle Database Schema Object Management

1. Open SQL Plus, the system user login BOOKSALE database.

system / tiger @booksale

2. Create a user bs in the following manner, and licensed to the user.

create user bs identified by bs default tablespace users;

grant resource,connect,create view to bs;

3. Use bs user login database, and the following related operations.

The relationship between the pattern book sales system design, create Tables 1 to 6.

①customers table:

create table customers(

customer_id number(4) primary key,

name char(20) not null,

phone varchar2(50) not null,

email varchar2(50),

address varchar2(200),

code varchar2(10)

);

 

②publishers table:

create table publishers(

publisher_id number(2) primary key,

name varchar2(50),

contact char(10),

phone varchar2(50)

);

③books table:

create table books(

ISBN varchar2(50) primary key,

title varchar2(50),

author varchar2(50),

pubdate date,

publisher_id number(2),

cost number(6,2),

retail number(6,2),

category varchar2(50),

foreign key(publisher_id) references publishers(publisher_id)

);

④orders table:

create table orders(

order_id number(4) primary key,

customer_id number(4),

orderdate date not null,

shipdate date,

shipaddress varchar2 (200),

shipcode varchar2(10),

foreign key(customer_id) references customers(customer_id)

);

⑤orderitem table:

create table orderitem(

order_id number(4),

item_id number(4),

ISBN varchar2(50) not null,

quantity number(4),

primary key(order_id,item_id),

foreign key(order_id) references orders(order_id)

);

 

⑥promotion table:

create table promotion(

gift_id number(2),

name char(20) primary key,

minretail number(5,2),

maxretail number(5,2)

);

5. Create a B- tree index on the name column of the CUSTOMERS table, index value required capital letters.

create index cus_name_index on customers(upper(name)) tablespace users;

6. Create a non-unique index on the title column BOOKS table.

create index book_title_index on books(title) tablespace users;

7. Create a unique index on the ISBN column ORDERitem table.

create unique index oitem_isbn_index on orderitem(ISBN) tablespace users;

8. Create a view customers_book, described in detail the customer and order information, including customer number, customer lists, order books ISBN, book title, the number of books, order date, delivery date.

create view customers_book(customer_id,name,ISBN,title,quantity,orderdate,shipdate)

as

select c.customer_id,c.name,o.ISBN,b.title,o.quantity,O.orderdate,O.shipdate

from customers c,orderitem o,orders O,books b;

9. Create a view customers_gift, describe the customer to obtain the gift of information, including customer name, the total price of books, gifts name.

create view customers_gift(customer_name,book_price,promotion_name)

as

select c.name,(case when oi.quantity<=10 then oi.quantity*b.retail else oi.quantity*b.cost end),p.name

from customers c,orderitem oi,books b,promotion p,orders o

where c.customer_id=o.customer_id and o.order_id=oi.order_id and b.ISBN=oi.ISBN and   

case when oi.quantity<=10 then oi.quantity*b.retail else oi.quantity*b.cost end between minretail and maxretail;

10. The definition of sequence seq_customers, generated customer ID sequence starting value of 1, step 1, no buffer, no circulation.

create sequence seq_customers start with 1 increment by 1 nocache nocycle;

11. Define sequence seq_orders, generating an order number, a starting value of the sequence 1000, in steps of 1, no buffer, no circulation.

create sequence seq_orders start with 1000 increment by 1 nocache nocycle;

12. The definition of sequence seq_promotion, generating gift number, sequence starting value of 1, step 1, no buffer, no circulation.

create sequence seq_promotion start with 1 increment by 1 nocache nocycle;

Published 53 original articles · won 117 Like · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_40431584/article/details/90082619