데이터베이스 빌 드 시트

2654 단어 Oacle 노트
데이터베이스 빌 드 시트
테스트 사용자: scott / tiger
슈퍼 관리자: sys / as sysdba
1. 건축 표
creat table 표 이름 (열 이름 데이터 형식 제약, 열 이름 데이터 형식 제약...)
데이터 형식
문자열: varchar (2) 길이 가 고정 되 지 않 은 nvarchar (1) char (10) 고정 길이 입 니 다. 빈 칸 nchar () 를 보충 할 수 없습니다.
숫자: number (7 정수, 0 소수)
날짜: date (7 - 7 월 - 2019 / 이 형식 을 제외 하고 모두 인식 되 지 않 음)
빅 데이터 형식
    /   

  blob(  4G)/clob

2. 제약
데이터 의 완전 성 확보: 정확, 유효
4 대 유형
               A、     (      ,    )  ,    

               B、    (              )  ,  ,   ,    

               C、     (   A/B,B          A      )      

                D、             ,  

주 키 제약 조건
primary key
1. 비 어 있 지 않 음 2. 유일한 3. 하나의 표 에 하나의 메 인 키 만 있 을 수 있 지만 하나의 메 인 키 는 여러 열 로 조합 할 수 있다.
문법
홈 키 제약 조건: alter table 표 이름
        add constraint pk_   primary key(  )

유일한 제약 조건 (데이터 만 유일 하고 비 어 있 지 않 으 며 빈 값 은 검증 되 지 않 습 니 다)
alter 테이블 테이블 이름
add constraint uq_열 이름 unique (열 이름)
검사 제약 조건: alter table 표 이름
add constraint ck_열 이름 check (조건 식)
관계 연산 자: > < > = < =! = < >
논리 연산 자: and or not
모호 일치: like
어댑터:
% 임의의 길이 와 일치 하 는 임의의 문자 (%. jpg 모든 jpg 파일)
_ 임의의 문자 일치
기본 값 제약 조건:
default
alter table 표 이름 modify 열 이름 default '값'
외부 키:
foreign key
A (학생) 메 인 표 B (성적) 서브 표 서브 표 는 메 인 표 의 데 이 터 를 참조 합 니 다.
A (계좌) B (소비 기록)
주 표 참조 시퀀스 는 주 키 여야 합 니 다.
서브 시계
alter 테이블 이름 add constraint fk열 이름 foreign key (외 키 열 이름) references 메 인 테이블 이름 (메 인 키 열 이름)
데 이 터 를 추가 할 때, 먼저 메 인 테이블 을 추가 하고, 하위 테이블 을 추가 합 니 다.
데 이 터 를 삭제 할 때, 먼저 하위 표를 삭제 한 다음, 메 인 표를 삭제 합 니 다.
eg:create table student
(stuid number(10) not null,
 stuname varchar2(20) not null,
 gender varchar(4) not null,
 phone varchar2(11) null
)
     
desc student;
  
select * from student;
    (    )
alter table student
add constraint pk_stuid primary key(stuid);
    (       ,     ,       )
alter table student
add constraint uq_phone unique(phone);
  
insert into student values('10001','  ',' ','12345678901')
    
alter table student 
add constraint ck_gender check(gender=' ' or gender=' ');
     
alter table student modify gender default ' ';
     

       
create table exam(
stuno number(10) not null,
subject varchar(30) not null,
score number(3) not null,
examdate date not null);
    
alter table exam add constraint fk_stuno foreign key(stuno) references student(stuid);
    
insert into exam values('10001'','java',87,sysdate);
    
          

좋은 웹페이지 즐겨찾기