473,549 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to setup default value using GETDATE?

kai
Hi, All
On Northwind database in SQL Server 2000, I try to setup default value at
table design windows for "OrderDate" using GETDATE(), but it does not work.
How do I use setup GETDATE default value for date type? Thanks

Kai
Jul 20 '05 #1
2 51408
On Sun, 09 May 2004 03:39:07 GMT, kai wrote:
Hi, All
On Northwind database in SQL Server 2000, I try to setup default value at
table design windows for "OrderDate" using GETDATE(), but it does not work.
How do I use setup GETDATE default value for date type? Thanks

Kai


Hi Kai,

ALTER TABLE MyTable
ADD DEFAULT GETDATE() FOR MyColumn
go

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
What do you mean exactly by 'it does not work'? Note that the default value
is used only when the column is omitted from the INSERT column list.

To add to Hugo's response, it's a good idea to name constraints explicitly
so that subsequent schema maintenance is easier:

ALTER TABLE MyTable
ADD CONSTRAINT DF_MyTable_MyCo lumn
DEFAULT GETDATE() FOR MyColumn

--
Hope this helps.

Dan Guzman
SQL Server MVP

"kai" <ka******@earth link.net> wrote in message
news:vJ******** *********@newsr ead3.news.atl.e arthlink.net...
Hi, All
On Northwind database in SQL Server 2000, I try to setup default value at table design windows for "OrderDate" using GETDATE(), but it does not work. How do I use setup GETDATE default value for date type? Thanks

Kai

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1744
by: garyusenet | last post by:
Using VB Express and SQL. I have an sql database. what function gives me todays date and time? and do i enter it in the 'default' property for the column in the database? i've tried now() date() date$()
3
2140
by: Dev | last post by:
Hello all, I am working on setting up a table that will append a sequence to the end of the value inserted. Example; INSERT INTO test (test) VALUES ('abcd'); And have the data in the database be; abcd0001 Now I do have things setup else where were the default value for the field
12
13852
by: Emi Lu | last post by:
Hello all, I have a question about "date" & "timestamp" types in PostgreSQL. I want to setup the default value '0000-00-00' and "0000-00-00 00:00:00" for them. However, it seems that PostgreSQL does not support it. Could someone helps me please? The example table: T1 (col1 varchar(7) not null,
2
3271
by: Bob | last post by:
I have a CreatedOn field , datetime, which has GetDate() as the default value in SQL server 2000 table. When I create a new record in the table itself in enterprise manager, the field gets populated OK, but when I try to create a new record with a Microsoft datagridview control, I notice that the datecreated value does not get created. It...
0
1258
by: zolof | last post by:
I have added a DetailsView to my WinForm configured in Insert mode. It binds to a database so when the user clicks on Insert button, the database is updated. I use a checkbox in my DetailsView: <asp:CheckBoxField DataField="CAN_REQUEST_LICENSE" /> How can I setup a default value to the checkbox will be checked by default ?
4
2248
by: erick-flores | last post by:
Hello I am trying to setup a default value for a field in a form. The field is a text box. I need to setup the default value to: 0.000. And whenever the user is trying to enter a value for this field, using the form, he ONLY can enter a value with that structure (0.000). eg. 1.234, 1.345, 6.543, 1.040, 0.003, 0.434. Can somebody tell me how...
2
11212
by: tezza98 | last post by:
Help please, Im using SQL server Management Studio Express and i want to change the default value of a varchar(50) column. i want the defaultdate to be like this '5/04/2007 11:15 pm System generated' So i have tried to do this: (getDate())+'System generated' (getdate()).'System generated' but neither seem to work
2
23402
by: vijaialphonse | last post by:
i have a table which has 3 columns, one of three is set to default value 0. Now i have to change data type of that particular column and its default value using sql query. am working with sql server 2005. am not getting any prob when i exec ALTER TABLE TABLE_NAME ADD COLUMN DATATYPE SIZE CONSTRAINT VALUE. but getting probs when exec ALTER...
5
5303
by: sourabhmca | last post by:
Hi friends, I have a table : create table abc (a int,b smalldatetime default getdate()) then insert value like insert into abc(a) values(1) now I want to change default value of column b be getdate()+(0.435) so how can I do ? please help. Its urgeny.
0
7551
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7750
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5396
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1971
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1084
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.