Difference between revisions of "MySQL"

Jump to navigation Jump to search
6 bytes removed ,  15:06, 18 January 2010
m
→‎Data Types: Minor format
m (→‎Data Types: Added SyntaxHighlight)
m (→‎Data Types: Minor format)
Line 36: Line 36:


To set a field to NULL, use NULL without any quotes eg...
To set a field to NULL, use NULL without any quotes eg...
<source lang="mysql">  
<source lang="mysql">INSERT INTO table (col1, col2) VALUES ('data1', NULL); </source>
INSERT INTO table (col1, col2) VALUES ('data1', NULL);  
</source>


=== IP Addresses ===
=== IP Addresses ===
IP addresses are most efficiently stored as an UNSIGNED INT, though obviously this isn't particularly human readable.   
IP addresses are most efficiently stored as an UNSIGNED INT, though obviously this isn't particularly human readable.   
MySQL will do the conversion between INT and dotted quad using the INET_ATON and INET_NTOA functions. For example;
MySQL will do the conversion between INT and dotted quad using the INET_ATON and INET_NTOA functions. For example;
<source lang="mysql">  
<source lang="mysql">SELECT INET_NTOA(ip) from ips;
SELECT INET_NTOA(ip) from ips;
INSERT INTO ips SET ip=INET_ATON('10.1.2.3');</source>
INSERT INTO ips SET ip=INET_ATON('10.1.2.3');
</source>
Alternatively, use VARCHAR(15) to store as text.
Alternatively, use VARCHAR(15) to store as text.


Navigation menu