데이터 베이스/MySQL
테이블 생성/삭제, CREATE TABLE, DROP TABLE
코끼리_땃쥐
2024. 5. 2. 14:24
반응형
CREATE TABLE
테이블을 생성하는 쿼리
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....);
형식으로 사용함
예시
CREATE TABLE ddatg.temp(
id int not null auto_increment,
name varchar(10) not null,
age int not null,
primary key(id)
)
ddatg라는 데이터 베이스에 temp라는 테이블을 생성,
테이블 컬럼
id는 int 형식 not null(비어있는 데이터 불가), auto_increment(자동 증가),
name은 varchar(10), not null,
age는 int 형식, not null 이며
프라이머리 키는 id로 설정
ddatg데이터베이스에 temp 테이블이 생성되었습니다.
자세한 내용 : https://www.w3schools.com/sql/sql_create_table.asp
DROP TABLE
테이블을 삭제하는 쿼리
DROP TABLE table_name
형식으로 사용함
예시
DROP TABLE ddatg.temp
ddatg 라는 데이터 베이스에 존재하는 temp 테이블을 삭제함.
테이블이 삭제되었습니다.
자세한 내용 : https://www.w3schools.com/sql/sql_drop_table.asp
반응형