2018 04 29 SQL - RYUDONGJIN/Memo_wiki GitHub Wiki

[SQL] ์›น ์„œ๋น„์Šค์˜ ์‚ฌ์šฉ์ž(ํšŒ์›)๋“ค ๊ฐ„์— ์ชฝ์ง€๋ฅผ ์ฃผ๊ณ  ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜๋Š” DDL์„ ์ž‘์„ฑํ•˜์„ธ์š”. ํ…Œ์ด๋ธ”์ด ์—ฌ๋Ÿฌ๊ฐœ ์—ฌ๋„ ์ข‹์Šต๋‹ˆ๋‹ค. ( Mysql ๋˜๋Š” Oracle )

ํšŒ์› DDL

CREATE TABLE `user` ( 
-- user table์ƒ์„ฑ
  `userID` varchar(20) NOT NULL, 
  `userPw` varchar(20) NOT NULL,
  `userPwCheck` varchar(20) NOT NULL, 
  -- ํŒจ์Šค์›Œ๋“œ๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ์ปฌ๋Ÿผ
  `userName` varchar(10) NOT NULL,
  `userBirth` varchar(20) NOT NULL,
  `userGender` varchar(10) NOT NULL,
  `userTel` varchar(20) NOT NULL,
  `userEmail` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`userID`) 
  -- userID์ปฌ๋Ÿผ์— PK๋ฅผ ๋ถ€์—ฌํ•˜์—ฌ ์ค‘๋ณต ID์ƒ์„ฑ ๋ฐฉ์ง€
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

์ชฝ์ง€ DDL

CREATE TABLE `chat` (
-- chat table์ƒ์„ฑ
  `chatNum` int(11) NOT NULL AUTO_INCREMENT,
  -- ์ชฝ์ง€ ๋ฐฉ๋งˆ๋‹ค ๊ตฌ๋ถ„์„ ์ฃผ๊ธฐ ์œ„ํ•œ chatNum ์ปฌ๋Ÿผ ์ƒ์„ฑ. 
  -- AUTO_INCREMENT๋ฅผ ๋ถ€์—ฌํ•˜์—ฌ ์ž๋™์œผ๋กœ ์ชฝ์ง€ ๋ฐฉ์˜ ID ์ƒ์„ฑ
  `fromID` varchar(20) NOT NULL,
  -- ๋ณด๋‚ด๋Š” ์‚ฌ๋žŒ ID
  `toID` varchar(20) NOT NULL,
  -- ๋ฐ›๋Š” ์‚ฌ๋žŒ ID
  `chatContent` varchar(200) NOT NULL,
  `chatTime` datetime NOT NULL,
  `chatRead` int(11) DEFAULT NULL,
  -- ์ชฝ์ง€๋ฅผ ์ฝ์—ˆ์„ ๋•Œ ์ƒํƒœ๊ฐ’ ๋ณ€ํ™”๋ฅผ ์œ„ํ•œ ์ปฌ๋Ÿผ
  `chatDelYN` varchar(5) NOT NULL,
  -- ์ชฝ์ง€๋ฅผ ์‚ญ์ œํ–ˆ์„ ๋•Œ ์ƒํƒœ๊ฐ’ ๋ณ€ํ™”๋ฅผ ์œ„ํ•œ ์ปฌ๋Ÿผ
  PRIMARY KEY (`chatNum`) 
  -- chatNum์ปฌ๋Ÿผ์œผ๋กœ ์ชฝ์ง€ ๋ฐฉ๋งˆ๋‹ค ๊ตฌ๋ถ„์„ ์ฃผ๊ธฐ ์œ„ํ•ด PK ๋ถ€์—ฌ
) ENGINE=InnoDB DEFAULT CHARSET=utf8;