Difference between revisions of "MySQL"

Jump to navigation Jump to search
141 bytes added ,  14:10, 13 January 2011
→‎INSERT / UPDATE Rows: Added further INSERT example
m (→‎CREATE / ALTER Tables: Minor format update)
(→‎INSERT / UPDATE Rows: Added further INSERT example)
Line 116: Line 116:
== INSERT / UPDATE Rows ==
== INSERT / UPDATE Rows ==
'''Basic Examples'''
'''Basic Examples'''
<source lang="mysql">INSERT INTO hosts (name, ping_ok) VALUES ('ServerA', 1) ON DUPLICATE KEY UPDATE ping_ok=1;
<source lang="mysql">
UPDATE hosts SET ping_ok=0, reason='Time Out' WHERE name='ServerA'; </source>
INSERT INTO hosts (name, ping_ok) VALUES ('ServerA', 1) ON DUPLICATE KEY UPDATE ping_ok=1;
INSERT IGNORE INTO hware2note (hid, nid);                # Ignores errors returned if insert would violate primary/unique key duplication
UPDATE hosts SET ping_ok=0, reason='Time Out' WHERE name='ServerA';  
</source>


<br>'''INSERT ... SELECT'''<br>
<br>'''INSERT ... SELECT'''<br>

Navigation menu