0
0
SQLquery~5 mins

INSERT with DEFAULT values in SQL

Choose your learning style9 modes available
Introduction
Sometimes you want to add a new row to a table and use the default values set for some or all columns. This saves time and keeps data consistent.
When you want to add a new record but rely on default settings for some columns.
When a column has a default value like current date or a fixed number and you don't want to type it every time.
When you want to insert a row without specifying any values, using all defaults.
When you want to quickly add a placeholder row with default values.
Syntax
SQL
INSERT INTO table_name DEFAULT VALUES;
This syntax inserts one row using all default values defined in the table.
It works only if all columns have default values or allow NULL.
Examples
Adds a new employee row using all default values set in the employees table.
SQL
INSERT INTO employees DEFAULT VALUES;
Inserts a new order row, explicitly using default values for order_date and status columns.
SQL
INSERT INTO orders (order_date, status) VALUES (DEFAULT, DEFAULT);
Sample Program
This creates a products table with default values for name and price. Then it inserts one row using all defaults. Finally, it shows the inserted row.
SQL
CREATE TABLE products (
  id SERIAL PRIMARY KEY,
  name VARCHAR(50) DEFAULT 'Unknown',
  price NUMERIC DEFAULT 0.0
);

INSERT INTO products DEFAULT VALUES;

SELECT * FROM products;
OutputSuccess
Important Notes
If a column does not have a default and does not allow NULL, using DEFAULT VALUES will cause an error.
DEFAULT VALUES inserts exactly one row.
You can also use DEFAULT keyword for specific columns in an INSERT statement.
Summary
Use INSERT ... DEFAULT VALUES to add a row with all default column values.
This is useful when defaults are set for columns and you want to save typing.
Make sure all columns have defaults or allow NULL to avoid errors.