
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Create MySQL datetime column with default 0000-00-00?
To set default, you can use the DEFAULT keyword in MySQL. Let us first create a table −
mysql> create table DemoTable -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeJoiningDate datetime default '0000-00-00 00:00:00' -> )ENGINE=MyISAM,AUTO_INCREMENT=100; Query OK, 0 rows affected (0.21 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(EmployeeName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(EmployeeName) values('David'); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(EmployeeName) values('Mike'); Query OK, 1 row affected (0.03 sec) mysql> insert into DemoTable(EmployeeName) values('Sam'); Query OK, 1 row affected (0.06 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------+--------------+---------------------+ | EmployeeId | EmployeeName | EmployeeJoiningDate | +------------+--------------+---------------------+ | 100 | Chris | 0000-00-00 00:00:00 | | 101 | David | 0000-00-00 00:00:00 | | 102 | Mike | 0000-00-00 00:00:00 | | 103 | Sam | 0000-00-00 00:00:00 | +------------+--------------+---------------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to order timestamp in descending order but place the timestamp 0000-00-00 00:00:00 first?
- How can I store ‘0000-00-00’ as a date in MySQL?
- In which format Year(2) or Year(4) MySQL will return the value of year from date ‘0000-00-00’?
- MySQL query to select date from 00:00 to today’s date
- Convert PHP variable “11:00 AM” to MySQL time format?
- Display hour in KK (00-11) format in Java
- Format hour in HH (00-23) format in Java
- Construct ∈-NFA of Regular Language L = (00)*1(11)*
- How to create boolean column in MySQL with false as default value?
- Construct ∈-NFA of Regular Language L = (0+1)*(00+ 11)
- 8085 Program to alternately display 00 and FF in the data field
- Create MySQL column with Key=MUL?
- Create a new table in MySQL with specific options with DEFAULT?
- Program to alternately display 00 and FF in the data field in 8085 Microprocessor
- How to compare DateTime Column with only Date not time in MySQL?

Advertisements