본문 바로가기
CLASS/MYSQL

#3-5 / 기타(enum,set,timestamp)

by eungSe__ 2024. 6. 4.

* enum : column에 옵션을 입력시킨 후 해당 옵션 외에는 값이 저장되지 않도록 하는 자료형 , ex) radio의 name값

=> radio일때 주로 사용

create table event(
no int(8) not null auto_increment, 
mid char(30) not null,
mpass varchar(10) not null,
mhp char(11) not null,
memaill varchar(40) not null,
mcode char(7) null,
moption enum('win','office','xbox') not null default 'win',
mdate timestamp not null default current_timestamp,
primary key(no),
unique key(mid)
);


insert into event values('0','hong','a1324','01009091004','hong@gmail.com','','xbox',now());

 

 

* set  : enum과 동일한 사항은 있으나, 해당 옵션을 여러개 값 저장 되도록 하는 기능이 있다

=> checkbox 일때 주로 사용

create table abc(
idx int(5) not null auto_increment,
agree enum('Y','N') not null default 'N', //radio
eventad set('sms','email','kakao','none') not null, // checkbox
primary key(idx)
);


insert into abc values ('0','Y','sms,email'); // 복수 선택 가능
insert into abc values ('0','Y','kakao');

 

 

 

* timestamp : sql서버의 시간을 가져와서 자동으로 현재시간을 적용시키는 자료형 (주의 : default current_timestamp)

  (설계할 때부터 timestamp 때려버리면 java에서 현재 시간을 따로 입력하지 않아도 됨)

  => insert 할때 now() 이용