

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a new table in MySQL with specific options with DEFAULT?
For this, use DEFAULT keyword after the column data type.
Let us create a table −
mysql> create table demo33 −> ( −> id int not null auto_increment primary key, −> name varchar(20) not null, −> start_date date default(current_date), −> end_date date default NULL, −> category enum('Good','Medium','Low') default 'Low' −> ); Query OK, 0 rows affected (2.32 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo33(name) values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo33(name,end_date,category) values('David','2020−12−21','Medium'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo33(name,start_date,category) values('David','2020−04−01','Good'); Query OK, 1 row affected (0.14 sec) mysql> insert into demo33(name,start_date,end_date,category) values('David','2020−03−10','2020−08−22','Good'); Query OK, 1 row affected (0.17 sec)
Display records from the table using select statement −
mysql> select *from demo33;
This will produce the following output −
+----+-------+------------+------------+----------+ | id | name | start_date | end_date | category | +----+-------+------------+------------+----------+ | 1 | John | 2020−10−28 | NULL | Low | | 2 | David | 2020−10−28 | 2020−12−21 | Medium | | 3 | David | 2020−04−01 | NULL | Good | | 4 | David | 2020−03−10 | 2020−08−22 | Good | +----+-------+------------+------------+----------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- Create a new database with MySQL Workbench?
- Delete only specific rows in a table with MySQL
- How to create a new table from merging two tables with MySQL union?
- Replace a specific duplicate record with a new value in MySQL
- Create a new user with password in MySQL 8?
- Create a temporary table with dates in MySQL
- Adding new column after a specific column and defining a default in MySQL?
- How can we create a new MySQL table by selecting specific column/s from another existing table?
- How to create a MySQL table with InnoDB engine table?
- How to create a MySQL table with MyISAM engine table?
- How to create a MySQL table with indexes?
- Display specific table names with MySQL LIKE Operator
- How to create a dialog with Neutral options?
- Adding a new column with the current time as a default value in MySQL?
- Create a new table with the properties of an old table and without duplicates using MySQL LIKE Operator?
Advertisements