473,382 Members | 1,225 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to set default value for a datetime column in mssql

10
Hi

I want to set the default value for a datetime datatype column not null as 2000-01-01 00:00:00.000 but the sql is not executing correctly. It is always inserting value as 1900-01-01 00:00:00.000

How to set the default value appropriately.

Appreciate any help.
Feb 1 '08 #1
2 27703
deepuv04
227 Expert 100+
Hi

I want to set the default value for a datetime datatype column not null as 2000-01-01 00:00:00.000 but the sql is not executing correctly. It is always inserting value as 1900-01-01 00:00:00.000

How to set the default value appropriately.

Appreciate any help.
hi,

try the following query, probably will help you


declare @t table
(
id int identity (1,1),
name varchar(100),
date datetime default (('2000-01-01'))
)

insert into @t(name,date) values('aaa',getdate())
insert into @t (name) values('bbb')
insert into @t(name,date) values('ccc',getdate())
insert into @t (name)values('ddd')
insert into @t (name,date)values('eee',getdate())

select * from @t

thanks
Feb 5 '08 #2
pks83
10
hi,

try the following query, probably will help you


declare @t table
(
id int identity (1,1),
name varchar(100),
date datetime default (('2000-01-01'))
)

insert into @t(name,date) values('aaa',getdate())
insert into @t (name) values('bbb')
insert into @t(name,date) values('ccc',getdate())
insert into @t (name)values('ddd')
insert into @t (name,date)values('eee',getdate())

select * from @t

thanks
Thanks i was able to fetch the details i needed using the convert function.

Thanks
Feb 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Phil Powell | last post by:
I have a mySQL database table with a column field datatype of datetime that I set up in the original create table statement like this: create table nnet_usermetadata ( .... nnet_record_entered...
0
by: Phil Ewington - 43 Plc | last post by:
Hi All, I am trying to use a function as a default value for a column but do not seem to get the desired result. I want to use the NOW() function for a last_updated column, here is my code... ...
2
by: Konstantin Zakharenko | last post by:
Hello, Our QA team have running a lot of test scripts (for automated regression testing), they run them on the different databases (Oracle/MS SQL). Several of those tests are dependent on the...
0
by: styko | last post by:
I'm retrieving data table from MSSQL 2000, and I would like to check if there is default value assign to specific column. So I'm checking DefaultValue property of a column and it returns null even...
4
by: Brian Brane | last post by:
I have properties that wrap DataRow columns as in: public int aNumber { get{ return m_DataRow; } set{ m_DataRow = value; } } If the column happens to contain DBNull, I get a cast exception...
5
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on more than one server. So, if I used a datetime field...
6
by: Manikandan | last post by:
Hi, I need to insert the datetime with milliseconds value into a datarow. My code as below DataTable testDataTable=new DataTable(); testDataTable.Columns.Add("updatedDateTime",...
4
by: pks83 | last post by:
In MSSQL I am using datetime as the column type and trying to execute the below mentioned query select time from tickets where ticket_id = '1'; when i execute the query on sql manager window it...
5
by: Almatrodi | last post by:
Hi I have in my DataSet a column of type DateTime. And, I want to change it's default to current date in DataSet view. I tried to use: - DateTime.Today - DateTime.Now -...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.