Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

Poner fecha por defecto a campo timestamp.

Estas en el tema de Poner fecha por defecto a campo timestamp. en el foro de SQL Server en Foros del Web. Hola a todos, estoy haciendo una migración de una base de datos MySql a MSSQL, pero me he encontrado con un detalle. En una tabla ...
  #1 (permalink)  
Antiguo 14/08/2009, 13:27
 
Fecha de Ingreso: julio-2008
Ubicación: Caldas, Antioquia, Colombia
Mensajes: 81
Antigüedad: 15 años, 10 meses
Puntos: 4
Poner fecha por defecto a campo timestamp.

Hola a todos,

estoy haciendo una migración de una base de datos MySql a MSSQL, pero me he encontrado con un detalle.
En una tabla tengo un campo (en la bd mysql) que tiene como valor por defecto CURRENT_TIMESTAMP, así que cuando se crea o actualiza éste campo toma el valor de la fecha actual (perfecto para un campo como fecha_modificacion o algo así). Pero no sé como hacer lo mismo en MSSQL, es posible??

Espero una pronta respuesta,

Gracias de antemano.
  #2 (permalink)  
Antiguo 14/08/2009, 13:39
Avatar de Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38
Respuesta: Poner fecha por defecto a campo timestamp.

No tienes que hacer nada, el campo se actualiza solo...


Saludos!

Como referencia, la ayuda de SQL Server 2000 (no mencionaste la version que utilizas) ....
Código:
timestamp 
The SQL Server timestamp data type has nothing to do with times or dates. SQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database. The timestamp data type was originally implemented to support the SQL Server recovery algorithms. Each time a page was modified, it was stamped with the current @@DBTS value and @@DBTS was incremented by one. This was sufficient for recovery to determine the relative sequence in which pages had been modified, but the timestamp values had no relationship to time.

In SQL Server version 7.0 and SQL Server 2000, @@DBTS is only incremented for use in timestamp columns. If a table contains a timestamp column, every time a row is modified by an INSERT, UPDATE, or DELETE statement, the timestamp value in the row is set to the current @@DBTS value, and then @@DBTS is incremented by one.

Never use timestamp columns in keys, especially primary keys, because the timestamp value changes every time the row is modified.

To record the times data modifications take place in a table, use either a datetime or smalldatetime data type to record the events and triggers to automatically update the values when any modification takes place.


Saludos!
__________________
La sencillez y naturalidad son el supremo y último fin de la cultura...
--
MCTS : SQL Server 2008, .NET Framework 3.5, ASP.NET Applications.
  #3 (permalink)  
Antiguo 14/08/2009, 15:09
Avatar de flaviovich  
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 8 meses
Puntos: 39
Respuesta: Poner fecha por defecto a campo timestamp.

Andres, no se refiere a poner un valor por defecto al campo?
Seria:
Código sql:
Ver original
  1. ALTER TABLE tutabla ALTER COLUMN fecha_modificacion datetime DEFAULT (getdate())
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.
  #4 (permalink)  
Antiguo 14/08/2009, 15:36
Avatar de Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38
Respuesta: Poner fecha por defecto a campo timestamp.

jejeje

okay, pense que se referia al tipo de dato timestamp


Saludos!
__________________
La sencillez y naturalidad son el supremo y último fin de la cultura...
--
MCTS : SQL Server 2008, .NET Framework 3.5, ASP.NET Applications.
  #5 (permalink)  
Antiguo 14/08/2009, 16:03
 
Fecha de Ingreso: julio-2008
Ubicación: Caldas, Antioquia, Colombia
Mensajes: 81
Antigüedad: 15 años, 10 meses
Puntos: 4
Respuesta: Poner fecha por defecto a campo timestamp.

jejeje si obviamente la confusión fue mía al pensar que el tipo de dato (timestamp) era igual al de mysql.

Gracias a los dos... ésa era la respuesta que buscaba.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:00.