DB프로그래밍/MYSQL

My SQL 기본키 설정

zelkova 2015. 7. 14. 11:49

<목차로 돌아가기>


기본키 설정하기

CREATE TABLE animals (
     id MEDIUMINT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
) ENGINE=MyISAM;

INSERT INTO animals (name) VALUES
    ('dog'),('cat'),('penguin'),
    ('lax'),('whale'),('ostrich');

SELECT * FROM animals;




기본키 설정하기 2

CREATE TABLE animals ( id MEDIUMINT NOT NULL AUTO_INCREMENT primary key, name CHAR(30) NOT NULL, ) ENGINE=MyISAM; INSERT INTO animals (name) VALUES ('dog'),('cat'),('penguin'), ('lax'),('whale'),('ostrich'); SELECT * FROM animals;




복수키 설정하기

CREATE TABLE animals (
    grp ENUM('fish','mammal','bird') NOT NULL,
    id MEDIUMINT NOT NULL AUTO_INCREMENT,
    name CHAR(30) NOT NULL,
    PRIMARY KEY (grp,id)
) ENGINE=MyISAM;

INSERT INTO animals (grp,name) VALUES
    ('mammal','dog'),('mammal','cat'),
    ('bird','penguin'),('fish','lax'),('mammal','whale'),
    ('bird','ostrich');

SELECT * FROM animals ORDER BY grp,id;


반응형

'DB프로그래밍 > MYSQL' 카테고리의 다른 글

MYSQL-where 문  (2) 2015.07.26
MySql 자료형  (0) 2015.07.15
MYSQL 계정추가하기  (0) 2015.06.25
My-SQL(ver5.619) 설치하기 (작업환경 : 윈도우7)  (0) 2014.06.05
Mysql - 현재 날자,시간  (0) 2011.04.06