Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is possible to add a timestamp column to a table? 1

Status
Not open for further replies.

cmonroy

Programmer
Mar 1, 2021
3
US
In other platforms, like SQL Server, you can create a table with automatic timestamp, like this:
create table sample (what integer, where char(8), when datetime default current_timestamp)

Thus, when you insert data in the tabke, like:
insert into sample (what, where) values (1, "Here")

The field when is updated as well with the current date and time:
1, "Here", 17-3-2021 12:42

Is there a way to do this in Visual Foxpro 9?







 
Yes, you can do the same thing in VFP, provided the table is part of a database. The field must be of DateTime data type.
Code:
CREATE TABLE Sample (SomeField T DEFAULT DateTime(), <more fields>)

I have not tried this myself, but I think it should work. Give it a try.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,

It also works with cursors

Code:
CLOSE ALL 

CREATE CURSOR csrDateTime (iRow I AUTOINC, cName C(12), tDateTime T DEFAULT DATETIME())

FOR i = 1 TO 20
	INSERT INTO csrDateTime (cName) VALUES ("N" + SYS(2015))
ENDFOR

BROWSE

CLOSE ALL
CLEAR ALL

hth

MarK

 
Excellent!
Thank you for your input. What I was missing was setting the table's default value for this particular use:

ALTER TABLE <ANYTABLE> [ADD/ALTER] <DATETIMEFIELD> DATETIME NOT NULL DEFAULT DATETIME().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top