본문 바로가기

데이터베이스

mqsql - 기본명령어(1)

728x90

데이터베이스 목록

show databases;

사용할 db 지정

use mysql;

(testtable기본 스키마로 지정되어있음)

현재 데이터베이스 테이블 목록

show tables;

특정 데이터베이스의 모든 테이블 나열

SHOW TABLES FROM 데이터베이스 LIKE '키워드%';

테이블 구조 (컬럼조회)

SHOW TABLES FROM 데이터베이스 LIKE '키워드%';

DESC testtable2;
show columns from testtable2;
show columns from testtable2 (in testbase);

테이블생성

create table testtable3 (num int not null, name varchar(30) not null, age int not null);

테이블 전체 조회

SELECT * FROM testtable2;

데이터 삽입

insert into testbase.testtable2 (id,username,email) value (346,'meme','mememail');

데이터 변경

update testbase.testtable2 
set username = 'momo' 
where username = 'meme';

데이터 삭제

delete from testbase.testtable2 where username = 'momo';

기본키 제약조건 추가

alter table testbase.testtable3 add primary key(num);
728x90

'데이터베이스' 카테고리의 다른 글

sql join 문 해결할 쿼리  (0) 2023.11.23
Mysql  (0) 2023.08.28