흰둥이는 코드를 짤 때 짖어 (왈!왈!왈!왈!왈!왈!왈!왈!왈!왈!왈!)

(MySQL) 기초 문법(테이블 복사) 본문

MySQL

(MySQL) 기초 문법(테이블 복사)

흰둥아솜사탕 2023. 3. 20. 17:40
728x90
반응형

orders 테이블

select * from orders;

orders 테이블

insert로 복사

create table orders2(
	no int not null,
    userid varchar(20) not null,
    product varchar(100) not null,
    cnt int default 1,
    regdate datetime default now(),
    foreign key(userid) references member(userid)
);
먼저 orders와 컬럼이 똑같은 orders2 테이블을 생성한다.
insert into orders2(select * from orders);
select * from orders2;

orders2 테이블

orders에 존재하는 데이터를 모두 복사하여 orders2에 저장하였다.

create로 복사

create table orders3(select * from orders);
select * from orders3;

orders3 테이블

orders3 테이블을 생성할 때 orders 테이블에 존재하는 데이터를 모두 복사하였다.
728x90
반응형

'MySQL' 카테고리의 다른 글

(MySQL) 기초 문법(뷰)  (0) 2023.03.21
(MySQL) 사용자  (1) 2023.03.21
(MySQL) 기초 문법(문자열 함수)  (0) 2023.03.20
(MySQL) 기초 문법(서브 쿼리)  (0) 2023.03.20
(MySQL) 기초 문법(유니온)  (1) 2023.03.20
Comments