
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a table with date column?
To create a table with only date column, you can use DATE type. Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentAdmissionDate DATE ); Query OK, 0 rows affected (0.47 sec)
Insert records in the table using INSERT command −
mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('Chris',now()); Query OK, 1 row affected, 1 warning (0.12 sec) mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('Robert',curdate()); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('David','2019-05-21'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using SELECT statement −
mysql> select * from DemoTable;
This will produce the following output −
+-----------+-------------+----------------------+ | StudentId | StudentName | StudentAdmissionDate | +-----------+-------------+----------------------+ | 1 | Chris | 2019-04-27 | | 2 | Robert | 2019-04-27 | | 3 | David | 2019-05-21 | +-----------+-------------+----------------------+ 3 rows in set (0.00 sec)
Advertisements