Jump to content

TimeStamp


Helio13
 Share

Recommended Posts

Boa tarde!

Estou com uma duvida para utilizar o timestmap do mysql

Eu quero transferir dados de uma tabela A para uma tabela B, mas queria que na tabela B houve um campo do tipo timstamp que me guarda se a data e hora em que o registo tinha sido transferido da tabela A para a B...

Como posso fazer isso?

Alguém me pode ajudar?

Obrigado

Cumprimentos

Link to comment
Share on other sites

INSERT INTO tabela2 (col1, col2, col3, time) 
   SELECT col1, col2, col3, NOW() as time FROM tabela1

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

Entendi isso, mas...

A partir deste codigo que tenho

INSERT INTO sip2.temporaria2 (select *
from sip2.temporaria
where sip2.temporaria.CODIGO_INVENTARIO not in
( select CODIGO_INVENTARIO from sip2.definitiva where sip2.temporaria.CODIGO_INVENTARIO = sip2.definitiva.CODIGO_INVENTARIO));

Que insere na tabela temporaria2 os registos que estao na tabela temporaria que não estão na tabela temporaria2...como meto aqui o timestamp?

Link to comment
Share on other sites

Pah, é mesmo só verificar se o CODIGO_INVENTARIO que estás a ir buscar à tabela temporaria não está já na temporaria2. Adicionas a coluna extra que pretendes adicionar à lista.

INSERT INTO temp2
   SELECT *, NOW() AS time_stamp
   FROM temp
   WHERE CODIGO_INVENTARIO NOT IN
       (SELECT CODIGO_INVENTARIO FROM temp2)

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.