Insert Date SQL Database example

Insert Date SQL Database example

To insert date value to the table where its column defined as date. In this example we will insert both date and datatime value to the table. Let’s first create table:

create table dbo.DateTest (
	test_id int identity not null,
	eventDate date null,
	createTime datetime default getdate() null,
	updateTime datetime null,
	primary key (test_id) 
)

As you see above we have create table four column where tast_id is primary which identity column means its value is incremental whenever new data inserted into the table and eventDate will take date, createTime column will take datetime with default value if we don’t include in insert statement, updateTime is also defined as datetime.

  • Insert statement to insert the data:
INSERT INTO OTC.dbo.DateTest(
  eventDate
  ,updateTime
) VALUES (
   '20151226' -- eventDate - IN date
   ,'12/26/2015 12:00:00 AM' -- updateTime - IN datetime
)
  • I have inserted data two time and below is results:

Insert Date SQL Database example

  • For more details please go through SQL documentation here

Leave a Reply

Your email address will not be published. Required fields are marked *