--1) SCORE 테이블과 동일한 구조를 갖는 SCORE_CHK를 생성하고 RESULT 60이상 90이하만 입력 가능하도록 하세요.
--2) STUDENT 테이블과 동일한 구조를 갖는 STUDENT_COPY 테이블을 생성하면서 SNO은 PK로 SNAME은 NOT NULL로 SYEAR의 DEFAULT는 1로
-- 설정하세요.
--3) COURSE 테이블과 동일한 구조를 갖는 COURSE_CONTSRAINT 테이블을 생성하면서 CNO, CNAME을 PK로 PNO은 PROFESSOR_PK의 PNO을 참조하여
-- FK로 설정하고 ST_NUM은 DEFAULT 2로 설정하세요.
--1) 다음 구조를 갖는 테이블을 생성하세요.
--PRODUCT 테이블 - PNO NUMBER PK : 제품번호
-- PNMAE VARCHAR2(50) : 제품이름
-- PRI NUMBER : 제품단가
--PAYMENT 테이블 - MNO NUMBER PK : 전표번호
-- PDATE DATE NOT NULL : 판매일자
-- CNAME VARCHAR2(50) NOT NULL : 고객명
-- TOTAL NUMBER TOTAL > 0 : 총액
--PAYMENT_DETAIL - MNO NUMBER PK FK : 전표번호
-- PNO NUMBER PK FK : 제품번호
-- AMOUNT NUMBER NOT NULL : 수량
-- PRICE NUMBER NOT NULL : 단가
-- TOTAL_PRICE NUMBER NOT NULL TOTAL_PRICE > 0 : 금액
select *
from ALL_CONSTRAINTS
where owner = 'C##EUNSUK';
select *
from ALL_CONSTRAINTS
where owner = 'C##EUNSUK';
select *
from ALL_CONSTRAINTS
where owner = 'C##EUNSUK';
create table empphaha
(
eno number primary key,
ename varchar(20),
sal number,
comm number,
constraint hahakikkik check (sal >= 3000),
constraint hahakk check (comm between 1 and 100)
);
select *
from empphaha;
insert into empphaha
values (1, 'eh', 3000, 1);
drop table empphaha;
create table emppaha
(
eno number,
sal number,
comm number,
constraint aeee check ( sal >= 3000 ),
constraint kehake check ( comm between 1 and 50 )
);
drop table emppaha;
create table ppp
(
eno number primary key,
ename varchar2(20)
);
create table hawehwg
(
eno number,
sal number,
constraint wegwee foreign key (eno)
references ppp (eno)
on delete cascade
);
alter table hawehwg
drop constraint wegwee;
alter table hawehwg
add constraint weg foreign key (eno) references ppp (eno);
create table t_boardaa
(
boardno number,
boardtitle varchar2(10),
constraint eeef primary key (boardno)
);
create table t_boardfile
(
boardno number,
boardtitle varchar2(20),
haha number,
constraint akak primary key
(boardno, haha),
constraint wekjwe foreign key (boardno) references t_boardaa (boardno)
);
select *
from t_boardaa;
select *
from t_boardfile;
insert into t_boardfile
values (2, '1', 3);
insert into t_boardaa
values (1, '2');
drop table t_boardaa;
drop table t_boardfile;
create table t_boardaa
(
bno number,
bno2 number
);
alter table t_boardaa
add constraint wefwef primary key (bno);
create table t_boardfile
(
bno number,
bno2 number,
bno3 number
constraint wegweg primary key (bno, bno2),
constraint wegweh foreign key (bno)
references t_boardaa (bno)
);
create table factory1
(
fno number primary key,
fname varchar2(50) not null,
loc varchar2(10)
);
create table goods1
(
gno number primary key,
gname varchar2(50),
pri number,
fno number,
constraint wegweg
foreign key (fno) references factory (fno)
);
create table prod1
(
pno number primary key,
gno number,
price number,
pdate date,
constraint wegg foreign key
(gno) references goods (gno)
);
alter table goods1
drop constraint wegweg;
alter table goods1
add constraint wegweg foreign key (fno) references factory1;
alter table prod1
drop constraint wegg;
alter table prod1
add constraint wegg foreign key (gno) references goods1 (gno);
////////////////////////////////////
여기부터 숙제
create table score_chk as (select *
from score);
drop table score_chk;
alter table score_chk
add constraint ahahae check (result >= 60 and result <= 90);
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////////////////////////
더 쉽게하는방법 없을까?;
////////
만들면서 집어넣으면서 키주는방법
select *
from score;
create table score_chk
(
sno number,
cno number,
result number,
constraint awegw check ( result >= 60 and result <= 90 )
);
insert into score_chk
values (1, 1, 60);
select *
from student;
create table studeont_copy
(
sno number,
sname varchar2(20) not null,
sex varchar2(3),
syear number(1) default 1,
major varchar2(20),
avr number(4, 2)
);
alter table studeont_copy
add constraint hahakiks primary key (sno);
select *
from course;
이미 만들어진 테이블의 칼럼 타입을 바꾸는방법은 없을까?
//////////////////////////////////////////
이미 만들어진 테이블의 칼럼 타입을 바꾸는방법은 없을까?
//////////////////////////////////////////
이미 만들어진 테이블의 칼럼 타입을 바꾸는방법은 없을까?
//////////////////////////////////////////
이미 만들어진 테이블의 칼럼 타입을 바꾸는방법은 없을까?
//////////////////////////////////////////
이미 만들어진 테이블의 칼럼 타입을 바꾸는방법은 없을까?
//////////////////////////////////////////
이미 만들어진 테이블의 칼럼 타입을 바꾸는방법은 없을까?
drop table course_constraint;
create table course_constraint
(
cno varchar2(9),
cname varchar2(20),
st_tum number(1) default 2,
pno number
);
alter table course_constraint
add constraint qwegqh primary key (cno, cname);
create table professor_pk
(
pno number primary key,
pname number
);
alter table course_constraint
add constraint erh4hhahr foreign key (pno) references professor_pk (pno);
create table T_SNS
(
sns_no number primary key,
sns_nm varchar2(20)
);
create table T_SNS_DETAIL
(
sns_no number primary key,
sns_ben number,
constraint efwegh foreign key (sns_no) references t_sns (sns_no)
);
create table T_SNS_UPLOADED
(
sns_no number,
SNS_UPL_NO number,
constraint awehh primary key (sns_no, SNS_UPL_NO),
constraint qerhh foreign key (sns_no) references T_SNS_DETAIL
--------------- 이거를 detail로 해야되나 아니면 그냥 sns로 해야되나???
--------------- 이거를 detail로 해야되나 아니면 그냥 sns로 해야되나???
--------------- 이거를 detail로 해야되나 아니면 그냥 sns로 해야되나???
--------------- 이거를 detail로 해야되나 아니면 그냥 sns로 해야되나???
--------------- 이거를 detail로 해야되나 아니면 그냥 sns로 해야되나???
--------------- 이거를 detail로 해야되나 아니면 그냥 sns로 해야되나???
--------------- 이거를 detail로 해야되나 아니면 그냥 sns로 해야되나???
--아니면 어차피 둘다 primary 키니까 뭘 해도 상관없는건가?
)
;
insert into t_sns
values (1, '페북');
insert into t_sns
values (2, '인스타');
insert into t_sns
values (3, '트위터');
insert into T_SNS_DETAIL
values (1, 4000);
insert into T_SNS_DETAIL
values (2, 10000);
insert into T_SNS_DETAIL
values (3, 30000);
insert into T_SNS_UPLOADED
values (1, 1);
insert into T_SNS_UPLOADED
values (1, 2);
insert into T_SNS_UPLOADED
values (2, 1);
insert into T_SNS_UPLOADED
values (2, 2);
select *
from T_SNS;
select *
from T_SNS_DETAIL;
select *
from T_SNS_UPLOADED;
//////////////////////////////////////
여기 한번 다시보기
;
create table product
(
pno number primary key,
pname varchar2(50),
pri number
);
create table payment
(
mno number primary key,
pdate date not null,
cname varchar2(50) not null,
total number,
constraint wgg check (total > 0)
);
////////////////////////////////////
프라이머리 키는 동시에 지정해야 하는가?;
create table payment_detail
(
mno number,
pno number,
amount number,
price number not null,
total_price number not null,
constraint wegeg primary key (mno, pno),
constraint wegh foreign key (mno) references payment (mno),
constraint whqhweg foreign key (pno) references product (pno)
);
create table bbb (mno number, pno number, cno number);
select * from bbb;
insert into bbb values (1,1,1);
insert into bbb values (1,2,1);
insert into bbb values (1,2,1);
insert into bbb values (1,63,1);
alter table bbb add constraint wegqwg primary key (mno,pno);
alter table whh drop constraint wrhhh;
alter table whh drop constraint qwrhqh;
drop table whh;
select * from bbb;
create table whh (pno number, mno number, price number, amount number, constraint wrhhh primary key (pno),
constraint qwrhqh foreign key (mno, pno) references bbb (mno, pno)
);
select * from whh;
insert into whh values (63,1,1,1);
insert into payment_detail values (1,1,1,1,1);
create table hahakik(sno number, sname number);
select * from hahakik;
alter table hahakik add (haha number);
alter table hahakik drop (haha);
alter table hahakik modify (haha varchar2(10));
댓글 영역