SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Current time as a default value
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rafael.soteldo
Starting Member

36 Posts

Posted - 09/26/2012 :  20:29:00  Show Profile  Reply with Quote
I have a DateTime field in a table, how can I set the current date/time as a default value for this field?

Thanks in advance for your time

-------
Rafael Soteldo

khtan
In (Som, Ni, Yak)

Singapore
17635 Posts

Posted - 09/26/2012 :  20:33:00  Show Profile  Reply with Quote
ALTER TABLE <table name>
  ADD CONSTRAINT <constraint name>
  DEFAULT getdate()
  FOR <column name>



KH
Time is always against us

Go to Top of Page

rafael.soteldo
Starting Member

36 Posts

Posted - 09/26/2012 :  21:32:27  Show Profile  Reply with Quote
Thank you.

And how do I set it when designing the table?, I wrote getdate() in "Default value or binding" and I got an error message.

By the way, how do I set your answer as the correct answer as in other forums?

Thanks in advance for your time

-------
Rafael Soteldo

Edited by - rafael.soteldo on 09/26/2012 21:35:13
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17635 Posts

Posted - 09/26/2012 :  21:55:43  Show Profile  Reply with Quote
quote:
And how do I set it when designing the table?, I wrote getdate() in "Default value or binding" and I got an error message.

what is the error message ?

if you are creating the table via CREATE TABLE command

CREATE TABLE <table name>
(
   <column name> datetime DEFAULT getdate()
)


quote:
By the way, how do I set your answer as the correct answer as in other forums?

this forum software does not has this feature


KH
Time is always against us

Go to Top of Page

rafael.soteldo
Starting Member

36 Posts

Posted - 09/27/2012 :  13:27:35  Show Profile  Reply with Quote
I'm using the visual designer that comes with SQL Server Management Studio 2008.

Can I use this function getdate() in the designer, or do I have to do it via sql code?

Thanks in advance for your time

-------
Rafael Soteldo

Edited by - rafael.soteldo on 09/27/2012 14:35:24
Go to Top of Page

DonAtWork
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 09/28/2012 :  08:54:08  Show Profile  Reply with Quote
in SSMS, when you use the designer, there is a column properties tab that you can use to input a default value.








How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page

rafael.soteldo
Starting Member

36 Posts

Posted - 09/28/2012 :  22:19:29  Show Profile  Reply with Quote
Thank you

Thanks in advance for your time

-------
Rafael Soteldo
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000