-
Notifications
You must be signed in to change notification settings - Fork 0
SQL
Oleh Astappiev edited this page Oct 16, 2023
·
1 revision
Instead of REPLACE INTO
use
INSERT INTO t1 (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE a=VALUES(a), b=VALUES(b), c=VALUES(c);
REPLACE INTO
causes problems when using Triggers or Foreign key constraints because it triggers the delete event.
- use snake case for column names, like
this_is_column_of_multiple_words
; - entity ID field should name name like
user_id
,resource_id
, NOT justid
; - use
TIMESTAMP
for metadata fields (likecreated_at
,updated_at
) and DATETIME, DATE, TIME for user defined values (likedate_of_birth
); - always add a default value for TIMESTAMP fields, like
DEFAULT CURRENT_TIMESTAMP
orON UPDATE CURRENT_TIMESTAMP