[TIL] SQL/Table

HYERINยท2024๋…„ 2์›” 3์ผ

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
2/13
post-thumbnail

๐Ÿ’ป ์‹ค์Šต

table ๋ฌธ๋ฒ•

table ์ƒ์„ฑ

create table tablename (
	columnname datatype,
    columnname datatype,
    ...
);

table ๋ชฉ๋กํ™•์ธ

show tables;

table ์ •๋ณดํ™•์ธ

desc tablename;

table name ๋ณ€๊ฒฝ

alter table tablename
rename new_tablename;

table column ์ถ”๊ฐ€

alter table tablename
add column columnname datatype;

table column ๋ณ€๊ฒฝ

alter table tablename
modify column columnname datatype; //datatype
alter table tablename
change column old_columnname new_columnname new_datatype; //name

table column ์‚ญ์ œ

alter table tablename
drop column columnname;

table ์‚ญ์ œ

drop table tablename;

๐Ÿงธ review

example table

create table example
(
   id int,
   name varchar(16)
);
  • age(int) column ์ถ”๊ฐ€
alter table example
add column age int;
  • old(int) column ์ถ”๊ฐ€
alter table example
add column old int;
  • age(int) column ์‚ญ์ œ
alter table example
drop column age;
  • old(int) โ†’ sex(char) column ๋ณ€๊ฒฝ
alter table example
change column old sex char;
  • animal table ์‚ญ์ œ
drop table animal;

๐Ÿšซ table ์ƒ์„ฑ ์ „์— ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ค์ •ํ•˜๊ธฐ

์‹ค์Šตํ™•์ธ


0๊ฐœ์˜ ๋Œ“๊ธ€