Good day,
Is there a way to add a field in a SQL table that automatically inserts a
date/time stamp when the record is created?
Thank you in advance...On Feb 27, 10:38=A0pm, PsyberFox <Psyber...@.discussions.microsoft.com>
wrote:
> Good day,
> Is there a way to add a field in a SQL table that automatically inserts a
> date/time stamp when the record is created?
> Thank you in advance...
You can do it by writing a an insert trigger on table.|||... or having a default value for the column. Of course, a default can be overridden by the INSERT
statement.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
<vinodkus@.gmail.com> wrote in message
news:746d44f8-b988-4950-b74a-b5d152515abc@.62g2000hsn.googlegroups.com...
On Feb 27, 10:38 pm, PsyberFox <Psyber...@.discussions.microsoft.com>
wrote:
> Good day,
> Is there a way to add a field in a SQL table that automatically inserts a
> date/time stamp when the record is created?
> Thank you in advance...
You can do it by writing a an insert trigger on table.|||"PsyberFox" <PsyberFox@.discussions.microsoft.com> wrote in message
news:9B7F88F8-B885-4A28-979B-9B43385D26FF@.microsoft.com...
> Good day,
> Is there a way to add a field in a SQL table that automatically inserts a
> date/time stamp when the record is created?
Just create it with a default of GETDATE() and make sure your procedure(s)
that insert into it don't specify a value for it
CREATE TABLE test (
dtmTimeStamp DATETIME DEFAULT GETDATE(),
[more columns]
)
If you need it to be 'secure' then as someone else mentioned you'll have to
create triggers to keep the value fixed and/or make sure an explicit value
can't be inserted.
Showing posts with label stamp. Show all posts
Showing posts with label stamp. Show all posts
Tuesday, February 14, 2012
Date/Time Stamp
When a record is written to a table (via a asp form), I'd like the time
and date from the server to automatically populate a column in that
table. From what I can tell, timestamp isn't working. I rather not
have the time come from the client.
and date from the server to automatically populate a column in that
table. From what I can tell, timestamp isn't working. I rather not
have the time come from the client.
Thanks for the help.Add a column with a default of CURRENT_TIMESTAMP. This is nothing to do
with TIMESTAMP, which is the SQL Server keyword for a row-versioning
column, not for date and time.
ALTER TABLE your_table ADD date_created DATETIME NOT NULL
CONSTRAINT df_your_table_date_created DEFAULT CURRENT_TIMESTAMP
--
David Portas
SQL Server MVP
--|||alternatively, you can also use as
ALTER TABLE your_table ADD date_created DATETIME NOT NULL
CONSTRAINT df_your_table_date_created DEFAULT getdate()
best Regards,
Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/
------------
*** Sent via Developersdex http://www.developersdex.com ***
Date/Time stamp
Hi All,
I have a script that adds the date/time stamp to a file in the following format:
200701120149PM.
here is the script:
set dttm=%~t1
for /F "tokens=1-6 delims=/: " %%i in ("%dttm%") do (
set date=%%k%%i%%j%%l%%m
)
I need to display the time as military. How can I do that?
Thanks.What is that?
Can't you use T-SQL?
What's the table definition (DDL) look like?|||This is a DOS command that displays the system date/time.
What table are you refering to?|||Well, since this is a MS SQL Server forum, you might want to ask a question about that, othwerwise, there might be another board that can help you out with DOS|||Definitely the wrong forum for this question. Nevertheless, I think the answer may depend on your regional settings; when I run it, the output is fine (ie, no AM/PM, just a military hour).
This site (http://www.robvanderwoude.com/index.html)has some good stuff on DOS scripts...
Regards,
hmscott
I have a script that adds the date/time stamp to a file in the following format:
200701120149PM.
here is the script:
set dttm=%~t1
for /F "tokens=1-6 delims=/: " %%i in ("%dttm%") do (
set date=%%k%%i%%j%%l%%m
)
I need to display the time as military. How can I do that?
Thanks.What is that?
Can't you use T-SQL?
What's the table definition (DDL) look like?|||This is a DOS command that displays the system date/time.
What table are you refering to?|||Well, since this is a MS SQL Server forum, you might want to ask a question about that, othwerwise, there might be another board that can help you out with DOS|||Definitely the wrong forum for this question. Nevertheless, I think the answer may depend on your regional settings; when I run it, the output is fine (ie, no AM/PM, just a military hour).
This site (http://www.robvanderwoude.com/index.html)has some good stuff on DOS scripts...
Regards,
hmscott
Date/Time Stamp
Good day,
Is there a way to add a field in a SQL table that automatically inserts a
date/time stamp when the record is created?
Thank you in advance...
On Feb 27, 10:38Xpm, PsyberFox <Psyber...@.discussions.microsoft.com>
wrote:
> Good day,
> Is there a way to add a field in a SQL table that automatically inserts a
> date/time stamp when the record is created?
> Thank you in advance...
You can do it by writing a an insert trigger on table.
|||"PsyberFox" <PsyberFox@.discussions.microsoft.com> wrote in message
news:9B7F88F8-B885-4A28-979B-9B43385D26FF@.microsoft.com...
> Good day,
> Is there a way to add a field in a SQL table that automatically inserts a
> date/time stamp when the record is created?
Just create it with a default of GETDATE() and make sure your procedure(s)
that insert into it don't specify a value for it
CREATE TABLE test (
dtmTimeStamp DATETIME DEFAULT GETDATE(),
[more columns]
)
If you need it to be 'secure' then as someone else mentioned you'll have to
create triggers to keep the value fixed and/or make sure an explicit value
can't be inserted.
Is there a way to add a field in a SQL table that automatically inserts a
date/time stamp when the record is created?
Thank you in advance...
On Feb 27, 10:38Xpm, PsyberFox <Psyber...@.discussions.microsoft.com>
wrote:
> Good day,
> Is there a way to add a field in a SQL table that automatically inserts a
> date/time stamp when the record is created?
> Thank you in advance...
You can do it by writing a an insert trigger on table.
|||"PsyberFox" <PsyberFox@.discussions.microsoft.com> wrote in message
news:9B7F88F8-B885-4A28-979B-9B43385D26FF@.microsoft.com...
> Good day,
> Is there a way to add a field in a SQL table that automatically inserts a
> date/time stamp when the record is created?
Just create it with a default of GETDATE() and make sure your procedure(s)
that insert into it don't specify a value for it
CREATE TABLE test (
dtmTimeStamp DATETIME DEFAULT GETDATE(),
[more columns]
)
If you need it to be 'secure' then as someone else mentioned you'll have to
create triggers to keep the value fixed and/or make sure an explicit value
can't be inserted.
Subscribe to:
Posts (Atom)