Stingeth
asked on
Is getdate() the same as CURRENT_TIMESTAMP in a query?
There are not real queries: ItemDate is a datetime column
SELECT * FROM Items WHERE ItemDate > CURRENT_TIMESTAMP
SELECT * FROM Items WHERE ItemDate > getdate()
Also, if you have a DateTime field, can you set it's default to be CURRENT_TIMESTAMP? Or should you use getdate() as it's default value?
I am understand the difference between the datetime column type and the timestamp column type, but I was wondering about the CURRENT_TIMESTAMP variable and if you can use it the same as getdate() in calculations etc.
SELECT * FROM Items WHERE ItemDate > CURRENT_TIMESTAMP
SELECT * FROM Items WHERE ItemDate > getdate()
Also, if you have a DateTime field, can you set it's default to be CURRENT_TIMESTAMP? Or should you use getdate() as it's default value?
I am understand the difference between the datetime column type and the timestamp column type, but I was wondering about the CURRENT_TIMESTAMP variable and if you can use it the same as getdate() in calculations etc.
Yes. There are both same.
Namasi
Namasi
u can also create a table that uses CURRENT_TIMESTAMP as a DEFAULT constraint
there is an example in the above link on how to create one....
there is an example in the above link on how to create one....
Hi,
Both are same, only thing is many of they are familiar with getdate() than CURRENT_TIMESTAMP. On seeing the CURRENT_TIMESTAMP many have to confusion, whether it wld give only the Timestamp (without date). So U can be clear, just check this example taken from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_cr-cz_60mo.asp page,
Use CURRENT_TIMESTAMP as a DEFAULT constraint
This example creates a table that uses CURRENT_TIMESTAMP as a DEFAULT constraint for the sales_date column of a sales row.
USE pubs
GO
CREATE TABLE sales2
(
sales_id int IDENTITY(10000, 1) NOT NULL,
cust_id int NOT NULL,
sales_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
sales_amt money NOT NULL,
delivery_date datetime NOT NULL DEFAULT DATEADD(dd, 10, GETDATE())
)
GO
INSERT sales2 (cust_id, sales_amt)
VALUES (20000, 550)
This query selects all information from the sales2 table.
USE pubs
GO
SELECT *
FROM sales2
GO
Here is the result set:
sales_id cust_id sales_date sales_amt delivery_date
----------- ---------- ------------------- --------- -------------------
10000 20000 Mar 4 1998 10:06AM 550.00 Mar 14 1998 10:06AM
(1 row(s) affected)
Rgds,
Pasha S...
Both are same, only thing is many of they are familiar with getdate() than CURRENT_TIMESTAMP. On seeing the CURRENT_TIMESTAMP many have to confusion, whether it wld give only the Timestamp (without date). So U can be clear, just check this example taken from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_cr-cz_60mo.asp page,
Use CURRENT_TIMESTAMP as a DEFAULT constraint
This example creates a table that uses CURRENT_TIMESTAMP as a DEFAULT constraint for the sales_date column of a sales row.
USE pubs
GO
CREATE TABLE sales2
(
sales_id int IDENTITY(10000, 1) NOT NULL,
cust_id int NOT NULL,
sales_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
sales_amt money NOT NULL,
delivery_date datetime NOT NULL DEFAULT DATEADD(dd, 10, GETDATE())
)
GO
INSERT sales2 (cust_id, sales_amt)
VALUES (20000, 550)
This query selects all information from the sales2 table.
USE pubs
GO
SELECT *
FROM sales2
GO
Here is the result set:
sales_id cust_id sales_date sales_amt delivery_date
----------- ---------- ------------------- --------- -------------------
10000 20000 Mar 4 1998 10:06AM 550.00 Mar 14 1998 10:06AM
(1 row(s) affected)
Rgds,
Pasha S...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Follow the link for extra documentation from msdn of microsoft
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_cr-cz_60mo.asp