Collections:
Omitting Columns in INSERT Statements in MySQL
How To Omit Columns with Default Values in INSERT Statement in MySQL?
✍: FYIcenter.com
If you don't want to specify values for columns that have default values, or you want to specify values to columns in an order different than how they are defined, you can provide a column list in the INSERT statement. If a column is omitted in the column, MySQL applies 3 rules:
The following tutorial exercise gives you some good examples:
mysql> INSERT INTO fyi_links (url, id)
VALUES ('sqa.fyicenter.com', 103);
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> INSERT INTO fyi_links (id) VALUES (110);
Query OK, 1 row affected, 1 warning (0.06 sec)
mysql> INSERT INTO fyi_links (url)
VALUES ('www.fyicenter.com');
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> SELECT id, url, notes, counts, DATE(created)
FROM fyi_links;
+-----+-------------------+-------+--------+---------------+
| id | url | notes | counts | DATE(created) |
+-----+-------------------+-------+--------+---------------+
| 101 | dev.fyicenter.com | NULL | 0 | 2006-04-30 |
| 102 | dba.fyicenter.com | NULL | 0 | 2006-07-01 |
| 103 | sqa.fyicenter.com | NULL | NULL | 2006-07-01 |
| 110 | | NULL | NULL | 2006-07-01 |
| 0 | www.fyicenter.com | NULL | NULL | 2006-07-01 |
+-----+-------------------+-------+--------+---------------+
5 rows in set (0.00 sec)
⇒ Violation of Unique Value Constraint in MySQL
⇐ Using Column Default Values in MySQL
2018-01-16, 2896🔥, 0💬
Popular Posts:
What Happens to Your Transactions When ERROR 1205 Occurred in MySQL? If your transaction receives th...
How To List All Stored Procedures in the Current Database in SQL Server Transact-SQL? If you want to...
How to execute statements in loops in SQL Server Transact-SQL? How to use WHILE ... loops? You can u...
How To Use GO Command in "sqlcmd" in SQL Server? "sqlcmd" is a command line client application to ru...
How To Format Time Zone in +/-hh:mm Format in SQL Server Transact-SQL? From the previous tutorial, y...