컬럼 레벨
create table newBook(
bookId number primary key,
bookname varchar2(50) not null,
publisher VARCHAR2(50) ,
price number
);
테이블 레벨
create table newBook(
bookId number,
bookname varchar2(50) not null,
publisher VARCHAR2(50),
price number,
primary key (bookId)
);
create table neworders(
orderId number,
custId number,
bookId number,
salePrice number ,
orderDate date default sysdate,
primary key (orderId),
foreign key(custId) references newcustomer(custId),
foreign key(bookId) references newbook(bookId)
);
alter table 테이블이름 add 컬럼이름 자료형;
💡 테이블에 값이 없다면 not null도 추가할 수 있지만 값이 있다면 레코드가 이미 존재해서 새로운 컬럼을 추가할 때는 not null 제약을 사용할 수없다.alter table 테이블이름 drop column 칼럼이름;
alter table 테이블이름 modify 컬럼이름 새로운 자료형;
alter table 테이블이름 add primary key(컬럼[들]);
💡 이작업을 할 때 컬럼이 중복된 값이 있거나 null 값이 있으면 불가능alter table newbook add primary key(bookId);
alter table newbook add check (price >= 1000);