Work

DB 실습간 예제 결과물

runicode 2009. 4. 8. 17:39





[1p]

table : product
attribute : no, name, price

table : customer
attribute : no, name, sex, age, phone

relation : sale

N:N cardinality (?) 다대다 카디널리티?

ERD를 그릴 것


*****

CREATE TABLE Product(
 PNO  NUMBER(4),
 PNAME  VARCHAR2(15),
 PRICE  NUMBER(8));

CREATE TABLE Customer(
 CNO  NUMBER(4),
 CNAME  VARCHAR2(15),
 SEX VARCHAR2(1),
 PHONE  VARCHAR2(15));

*****


[2p]

ERD는 3개의 테이블로 표시.
table : product, customer, sale


[3p]

제약조건 추가(update?)

product
- no is primary key
- name 중복되지 않음.
- price 1000~10000

customer
- no is primary key
- name is NOT NULL
- sex is male or female (혹은 M or F)

sale
- saleNo, customerNo


*****

CREATE TABLE Product(
 PNO  NUMBER(4) PRIMARY KEY,
 PNAME  VARCHAR2(15) UNIQUE,
 PRICE  NUMBER(8) CHECK (PRICE >= 1000 AND PRICE <= 10000)
);

CREATE TABLE Customer(
 CNO  NUMBER(4) PRIMARY KEY,
 CNAME  VARCHAR2(15) NOT NULL,
 SEX VARCHAR2(6) CHECK (SEX='Male' OR SEX='Female'),
 PHONE  VARCHAR2(15)
);

CREATE TABLE Sale(
 PNO NUMBER(4),
 CNO NUMBER(4),
 CONSTRAINT S_PK PRIMARY KEY(PNO, CNO),
 CONSTRAINT P_FK FOREIGN KEY(PNO) REFERENCES Product(PNO),
 CONSTRAINT C_FK FOREIGN KEY(CNO) REFERENCES Customer(CNO)
);

*****


[4p]

- 각 테이블에 10개 이상 데이터 추가

INSERT INTO Product VALUES(1, 'Ball_Soccer', 9000);
INSERT INTO Product VALUES(2, 'Ball_Baseball', 2000);
INSERT INTO Product VALUES(3, 'Ball_Basket', 10000);
INSERT INTO Product VALUES(4, 'Toy_Rabbit', 5000);
INSERT INTO Product VALUES(5, 'Toy_Mashimaro', 3000);
INSERT INTO Product VALUES(6, 'Toy_Frog', 2000);
INSERT INTO Product VALUES(7, 'Toy_Babi', 8000);
INSERT INTO Product VALUES(8, 'Robot_Dog', 7500);
INSERT INTO Product VALUES(9, 'Robot_AIMO', 10000);
INSERT INTO Product VALUES(10, 'Robot_UFO', 8000);

INSERT INTO Customer VALUES(1, 'Pola', 'F', '02-000-0000');
INSERT INTO Customer VALUES(2, 'David', 'M', '02-000-0000');
INSERT INTO Customer VALUES(3, 'Lovisa', 'F', '02-000-0000');
INSERT INTO Customer VALUES(4, 'Paul', 'M', '02-000-0000');
INSERT INTO Customer VALUES(5, 'Samuel', 'M', '02-000-0000');
INSERT INTO Customer VALUES(6, 'Jane', 'F', '02-000-0000');
INSERT INTO Customer VALUES(7, 'Bael', 'M', '02-000-0000');
INSERT INTO Customer VALUES(8, 'July', 'F', '02-000-0000');
INSERT INTO Customer VALUES(9, 'Nana', 'F', '02-000-0000');
INSERT INTO Customer VALUES(10, 'Lawn', 'M', '02-000-0000');


- 테이블 생성 및 데이터 추가 스크립트 생성.
: createtable.sql

[5p]

create view
- create view price > 3000
- update view price > 4000
상품명 수정

CREATE or REPLACE VIEW view1
 AS SELECT *
 FROM Product
 WHERE PRICE>=3000;

CREATE or REPLACE VIEW view1
 AS SELECT *
 FROM Product
 WHERE PRICE>=4000;


공지 - 4월 10일 퀴즈1 실시
텀 프로젝트 공지.