본문 바로가기
데이터베이스

MySQL 테이블

by 승환파크 2023. 5. 26.

표 형태로 구성된 2차원 구조이며 행과 열로 구성되어있다.

행은 로우(row) 또는 레코드(record)라고 부르며 열은 컬럼(column) 혹은 필드(field)라고 부른다.

엑셀과 상당히 유사한 형태를 나타내고 있다.

 

테이블 만들기

1.member 테이블 생성하기

컬럼명 자료형 조건
mem_id char(8) not null, primary key
mem_name varchar(10) not null
mem_number tinyint not null
addr char(2) not null
phone1 char(2)  
phone2 char(8)  
height tinyint unsigned
debut_date date  

위의 표와 같이 생긴 테이블 생성하기

create table member(
	mem_id char(8) not null primary key,
	mem_name varchar(10) not null,
	mem_number tinyint not null,
	addr char(2) not null,
	phone1 char(3),
	phone2 char(8),
	height tinyint unsigned,
	debut_date date
);

 

2. buy테이블 생성하기

컬럼명 자료형 조건
num int not null, primary key
mem_id char(8) not null, foreign key
prod_name char(6) not null
group_name char(4)  
price int unsigned, not null
amount smallint unsigned, not null

위의 표와 같이 생긴 테이블 생성하기

create table buy(
	num int not null primary key auto_increment,
	mem_id char(8) not null,
	prod_name char(6) not null,
	group_name char(4),
	price int unsigned not null,
	amount smallint unsigned not null,
	foreign key (mem_id) references member(mem_id)
);

'데이터베이스' 카테고리의 다른 글

MySQL 뷰  (0) 2023.05.26
MySQL 제약조건  (0) 2023.05.26
MySQL 동적sql  (0) 2023.05.26
MySQL 프로그래밍  (0) 2023.05.26
MySQL 스토어드 프로시저  (1) 2023.05.25