Skip to content

Latest commit

ย 

History

History
51 lines (29 loc) ยท 1.35 KB

Hard Delete & Soft Delete.md

File metadata and controls

51 lines (29 loc) ยท 1.35 KB

Hard Delete & Soft Delete

Assembled by GimuneLee (2020-01-13)


Hard Delete

  • ์ผ๋ฐ˜์ ์ธ ์‚ญ์ œ
  • Soft Delete์˜ ๋ฐ˜๋Œ€ ๊ฐœ๋…์ด๋ผ๋Š” ์˜๋ฏธ๋กœ 'Hard'๋ฅผ ๋ถ™์ธ ๊ฒƒ
  • SQL DELETE ๋ฌธ ์‚ฌ์šฉ

Soft Delete

  • ์ผ๋ฐ˜์ ์ธ ์‚ญ์ œ ๋Œ€์‹  removed ์ปฌ๋Ÿผ์„ ๊ฐฑ์‹ (SQL UPDATE ๋ฌธ ์‚ฌ์šฉ)ํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

  • ์ปฌ๋Ÿผ๋ช…์€ ๋ณดํ†ต removed , deleted_at , is_deleted ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • ์ปฌ๋Ÿผ์˜ ์ž๋ฃŒํ˜•์€ boolean ๋˜๋Š” datetime ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

    ex) ์‚ญ์ œ๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ๋Š” removed ์ปฌ๋Ÿผ๊ฐ’์ด NULL , ์‚ญ์ œ๋œ ๋ฐ์ดํ„ฐ๋Š” removed ๊ฐ’์ด ์‚ญ์ œ๋œ ์ผ์‹œ

  • ๋ณต๊ตฌํ•˜๊ฑฐ๋‚˜ ์˜ˆ์ „ ๊ธฐ๋ก์„ ํ™•์ธํ•˜๊ณ ์ž ํ•  ๋•Œ ๊ฐ„ํŽธํ•ฉ๋‹ˆ๋‹ค.

  • ๋‹ค๋ฅธ ํ…Œ์ด๋ธ”๊ณผ JOIN ์‹œ์— ํ•ญ์ƒ removed ๋ฅผ ์ ๊ฒ€ํ•ด์•ผ ํ•˜๋ฏ€๋กœ ๋ถˆํŽธํ•˜๋ฉฐ ์†๋„๋„ ๋Š๋ฆฝ๋‹ˆ๋‹ค.


SQL ๋ฌธ ๋น„๊ต

Hard Delete (์ผ๋ฐ˜์ ์ธ ์‚ญ์ œ)

DELETE FROM customer WHERE id=112;

Soft Delete

UPDATE customer SET deleted=NOW() WHERE id=112;

Soft Delete์—์„œ ์‚ญ์ œ๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” ์ปฌ๋Ÿผ์˜ ํƒ€์ž…์€ boolean ๋ณด๋‹ค๋Š” datetime (์‚ญ์ œ๋œ ์‹œ๊ฐ„)์„ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.


Reference & Additional Resources