개발자의 서재

[mariaDB] CREATE 문 예시들 본문

DB

[mariaDB] CREATE 문 예시들

ironmask431 2022. 3. 18. 08:34

create table POSTS (
id bigint not null auto_increment  -- 자동증가옵션
, create_date datetime
, modified_date datetime
, author TEXT not null  -- null 비허용
, content TEXT not null
, title varchar(500) not null
, primary key (id)  -- pk설정
);

create table BUILDING (
	CODE VARCHAR(5)
	,NAME VARCHAR(100)
	,primary key (CODE)
);


create table TIMETABLE (
	CODE VARCHAR(5)
	,day VARCHAR(3)
	,STARTTIME DATETIME
	,ENDTIME DATETIME
	,primary key (CODE)
);


create table CLASSROOM (
	CODE VARCHAR(10)
	,NAME VARCHAR (100)
	,BUILDINGCODE VARCHAR(5)
	,foreign KEY(CODE) references BUILDING(CODE)  -- 다른테이블 컬럼 외래키설정
);

create table BOOK (
	BOOKNUM bigint auto_increment
	,CLASSROOMCODE VARCHAR(10) unique  -- 중복비허용
	,TIMETABLECODE VARCHAR(5) unique
	,BOOKER VARCHAR(100)
	,primary key (BOOKNUM)
	,foreign KEY(CLASSROOMCODE) references CLASSROOM(CODE)
	,foreign KEY(TIMETABLECODE) references TIMETABLE(CODE)
);
Comments