[응용문제]
회원가입시 바로 1000포인트가 지급되게 제작
member table, point table + trigger
create table member(
idx int(4) not null auto_increment,
id varchar(30) not null,
pw varchar(30) not null,
name varchar(30) not null,
tss enum('SKT','KT','LGT','알뜰폰') not null default 'SKT',
phone char(11) not null,
post char(6) not null,
adr1 varchar(50) not null,
adr2 varchar(50) not null,
sex enum('male','female') not null default 'male',
birth char(8) not null,
rest enum('Y','N') not null default 'N',
bank char(20) not null,
joindate timestamp not null default current_timestamp,
primary key(idx),
unique id(id),
unique phone(phone)
);
create table point(
id char(20) not null,
point int(100) not null,
joindate timestamp not null default current_timestamp,
foreign key(id) references member (id)
);
delimiter $$
create trigger insert_point
after insert
on member
for each row
begin
insert into point (id,point,joindate) values (new.id,'0',new.joindate);
update point set point='1000';
end $$
delimiter;
insert into member values('0','hong','a1324','홍길동','SKT','01012345678','123456','주소1','주소2','female','931214','Y','',now());
🔽 선생님
create table member(
idx int(4) not null auto_increment,
id varchar(30) not null,
pw varchar(30) not null,
name varchar(30) not null,
tss enum('SKT','KT','LGT','알뜰폰') not null default 'SKT',
phone char(11) not null,
post char(5) not null,
adr1 varchar(200) not null, //50으론 모자름
adr2 varchar(200) not null,
sex enum('male','female') not null default 'male',
birth char(8) not null,
rest enum('Y','N') not null default 'N',
bank char(20) not null,
joindate timestamp not null default current_timestamp,
primary key(idx),
unique id(id),
unique phone(phone)
);
create table point(
id char(20) not null,
point int(100) not null,
joindate timestamp not null default current_timestamp,
foreign key(id) references member (id)
);
delimiter $$
create trigger insert_point
after insert
on member
for each row
begin
insert into point (id,point,joindate) values (new.id,'1000',now()); //now 넣어도 됨
//update point set point='1000'; //insert시 그냥 넣어주면 됨
end $$
delimiter;
insert into member values('0','hong','a1324','홍길동','SKT','01012345678','123456','주소1','주소2','female','931214','Y','',now());
⚡ signed / unsigned
signed
- 기본 default형 자료형(-25621 ~ 25621)
- (default가 signed라 singed는 따로 작성해줄 필요 없다)
unsigned
- 정수 기준 음수를 사용하지 않고 양수만 사용하며, 음수만큼 양수값이 늘어나있는 형태(1~ 51221)
- int에 많이 사용, 가격 등에 사용한다
create table abc(
idx int(5) unsigned not null auto_increment, //이렇게 써주는게 좋음
agree enum('Y','N') not null default 'N', //radio
eventad set('sms','email','kakao','none') not null, // ckbox
primary key(idx)
);
'CLASS > DATABASE' 카테고리의 다른 글
🌸 Oracle Setting (0) | 2024.08.21 |
---|---|
mysql -> json 변환 사이트 (0) | 2024.07.01 |
#5-1 / 각종 key 상세,trigger - 실무 (0) | 2024.06.10 |
#4-2 / view 응용 문제 , view select가 안됨 해결-권한문제 (0) | 2024.06.05 |
#4-1 / group by , table및 column 복제 등 (0) | 2024.06.05 |