USE market_db;
CREATE TABLE TABLE1(
col1 INT PRIMARY KEY,
col2 INT,
col3 INT
);
고유 키도 인덱스가 자동으로 생성된다.
CREATE TABLE TABLE2(
col1 INT PRIMARY KEY,
col2 INT UNIQUE,
col3 INT UNIQUE
);
SHOW INDEX FROM TABLE2;
USE market_db;
DROP TABLE if EXISTS buy, member;
CREATE TABLE member
(mem_id CHAR(8),
mem_name VARCHAR(10),
mem_number INT,
addr CHAR(2)
);
INSERT INTO member VALUES('TWC', '트와이스', 9, '서울');
INSERT INTO member VALUES('BLK', '블랙핑크', 4, '경남');
INSERT INTO member VALUES('WMN', '여자친구', 6, '경기');
INSERT INTO member VALUES('OMY', '오마이걸', 7, '서울');
SELECT * FROM member;
mem_id 열을 기본 키로 설정하고 내용 확인
ALTER TABLE member
ADD CONSTRAINT
PRIMARY KEY(mem_id);
SELECT * FROM member;
아이디를 기준으로 정렬 순서가 바뀜
DROP TABLE if EXISTS member;
CREATE TABLE member
(mem_id CHAR(8),
mem_name VARCHAR(10),
mem_number INT,
addr CHAR(2)
);
INSERT INTO member VALUES('TWC', '트와이스', 9, '서울');
INSERT INTO member VALUES('BLK', '블랙핑크', 4, '경남');
INSERT INTO member VALUES('WMN', '여자친구', 6, '경기');
INSERT INTO member VALUES('OMY', '오마이걸', 7, '서울');
SELECT * FROM member;
ALTER TABLE member
ADD CONSTRAINT
UNIQUE(mem_id);
SELECT * FROM member;
순서가 변경되지 않는다