본문 바로가기
It Study/프로그래밍 공부

mySQL 기본 예제(데이터베이스 생성 및 테이블 생성)

by prlkt5200 2024. 9. 23.
반응형
drop database if exists madang;
create database madangdb;
use madangdb;



create table booktbl(
bookid int auto_increment not null primary key ,
bookname varchar(20) not null,
publisher varchar(10) not null,
price int not null);



create table customertbl(
cusid int auto_increment not null primary key,
name varchar(5) not null,
address varchar(20) not null,
phone varchar(20));




create table orderstbl(
orderid int auto_increment not null primary key,
cusid int not null, 
bookid int not null,
saleprice int not null,
orderdate date not null,


foreign key(cusid) references customer(csuid),
foreign key(bookid) references book(bookid)
); 


insert into booktbl values (null, '축구의 역사', '굿스포츠', 7000);
insert into booktbl values (null, '축구아는 여자', '나무수', 13000);
insert into booktbl values (null, '축구의 이해', '대한미디어', 22000);
insert into booktbl values (null, '골프 바이블', '대한미디어', 35000);
insert into booktbl values (null, '피겨 교본', '굿스포츠', 8000);
insert into booktbl values (null, '역도 단계별기술', '굿스포츠', 6000);
insert into booktbl values (null, '야구의 추억', '이상미디어', 20000);
insert into booktbl values (null, '야구를 부탁해', '이상미디어', 13000);
insert into booktbl values (null, '올림픽 이야기', '삼성당', 7500);
insert into booktbl values (null, '올림픽 챔피언', 'pearson', 13000);



insert into customertbl values (null, '박지성', '영국 맨체스타', '010-5000-0001');
insert into customertbl values (null, '김연아', '대한민국 서울', '010-6000-0001');
insert into customertbl values (null, '장미란', '대한민국 강원도', '010-7000-0001');
insert into customertbl values (null, '추신수', '미국 클리블랜드', '010-8000-0001');
insert into customertbl values (null, '박세리', '대한민국 대전', null);



insert into orderstbl values (null, '1', '1', 6000,'2014-07-01');
insert into orderstbl  values (null, '1', '3', 21000,'2014-07-03');
insert into orderstbl  values (null, '2', '5', 8000,'2014-07-03');
insert into orderstbl  values (null, '3', '6', 6000,'2014-07-04');
insert into orderstbl  values (null, '4', '7', 20000,'2014-07-05');
insert into orderstbl  values (null, '1', '2', 12000,'2014-07-07');
insert into orderstbl  values (null, '4', '8', 13000,'2014-07-07');
insert into orderstbl  values (null, '3', '10', 12000,'2014-07-08');
insert into orderstbl  values (null, '2', '10', 7000,'2014-07-09');
insert into orderstbl  values (null, '3', '8', 13000,'2014-07-10');


select * from booktbl;
select * from customertbl;
select * from orderstbl;

 

반응형