Computer Science/Database

W3Schools SQL | #42 SQL ALTER TABLE 구문

토마토. 2022. 10. 29. 10:30

SQL ALTER TABLE Statement

SQL ALTER TABLE Statement

기존 테이블의 구조를 변경할 때 사용하는 명령어
ALTER - ADD, DROP, ALTER, MODIFY로 세분화된다.

ALTER TABLE - ADD COLUMN

ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE Customers
ADD Email varchar(255);

ALTER TABLE - DROP COLUMN

ALTER TABLE table_name
DROP COLUMN column_name;
ALTER TABLE Customers
DROP COLUMN Email;

ALTER TABLE - ALTER/MODIFY COLUMN

ALTER TABLE table_name
ALTER COLUMN column_name datatype;

SQL ALTER TABLE Example

ALTER TABLE Persons
ADD DateOfBirth date;

Change Data Type Example

ALTER TABLE Persons
ALTER COLUMN dateOfBirth year;

DROP COLUMN Example

ALTER TABLE Persons
DROP COLUMN DateOfBirth;