Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Backing up from one table to another and adding date/time ..

 
   Database Forums (Home) -> PHP SQL RSS
Next:  sort based on substring  
Author Message
Kenoli

External


Since: Jan 22, 2008
Posts: 3



(Msg. 1) Posted: Tue Jan 22, 2008 12:29 pm
Post subject: Backing up from one table to another and adding date/time information
Archived from groups: alt>php>sql (more info?)

I want to insert the data from one record in one table into another
table in a mysql database, adding the current date and time to a field
in the table the data is going into. Thus when a record is changed, I
am backing it up and indicating the date and time of the backup in a
"date" field.

The following is the method for copying data from a field in one table
to another.

INSERT INTO tbl_2 (fld_1, fld_2) SELECT tbl_1.fld_1, tbl_1.fld_2 FROM
tb_1 WHERE tbl_1.fld_id = [some record number];

How can I mix this with adding the new date/time data to a date field
in table 2 as well?

Thanks,

--Kenoli

 >> Stay informed about: Backing up from one table to another and adding date/time .. 
Back to top
Login to vote
ZeldorBlat

External


Since: Apr 17, 2007
Posts: 44



(Msg. 2) Posted: Tue Jan 22, 2008 1:00 pm
Post subject: Re: Backing up from one table to another and adding date/time [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jan 22, 3:29 pm, Kenoli wrote:
> I want to insert the data from one record in one table into another
> table in a mysql database, adding the current date and time to a field
> in the table the data is going into. Thus when a record is changed, I
> am backing it up and indicating the date and time of the backup in a
> "date" field.
>
> The following is the method for copying data from a field in one table
> to another.
>
> INSERT INTO tbl_2 (fld_1, fld_2) SELECT tbl_1.fld_1, tbl_1.fld_2 FROM
> tb_1 WHERE tbl_1.fld_id = [some record number];
>
> How can I mix this with adding the new date/time data to a date field
> in table 2 as well?
>
> Thanks,
>
> --Kenoli

Just include another column with the value of NOW():

INSERT INTO tbl_2 (fld_1, fld_2, fld_date)
SELECT tbl_1.fld_1, tbl_1.fld_2, NOW()
FROM tb_1
WHERE tbl_1.fld_id = [some record number];

 >> Stay informed about: Backing up from one table to another and adding date/time .. 
Back to top
Login to vote
Kenoli

External


Since: Jan 22, 2008
Posts: 3



(Msg. 3) Posted: Tue Jan 22, 2008 4:15 pm
Post subject: Re: Backing up from one table to another and adding date/time [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jan 22, 1:00 pm, ZeldorBlat wrote:
> On Jan 22, 3:29 pm, Kenoli wrote:
>
>
>
> > I want to insert the data from one record in one table into another
> > table in a mysql database, adding the current date and time to a field
> > in the table the data is going into.  Thus when a record is changed, I
> > am backing it up and indicating the date and time of the backup in a
> > "date" field.
>
> > The following is the method for copying data from a field in one table
> > to another.
>
> > INSERT INTO tbl_2 (fld_1, fld_2) SELECT tbl_1.fld_1, tbl_1.fld_2 FROM
> > tb_1 WHERE tbl_1.fld_id = [some record number];
>
> > How can I mix this with adding the new date/time data to a date field
> > in table 2 as well?
>
> > Thanks,
>
> > --Kenoli
>
> Just include another column with the value of NOW():
>
> INSERT INTO tbl_2 (fld_1, fld_2, fld_date)
> SELECT tbl_1.fld_1, tbl_1.fld_2, NOW()
> FROM tb_1
> WHERE tbl_1.fld_id = [some record number];

Thanks. I'll try it. And it won't get confused looking for a NOW()
field in tbl_1?

--Kenoli
 >> Stay informed about: Backing up from one table to another and adding date/time .. 
Back to top
Login to vote
Captain Paralytic

External


Since: Apr 23, 2007
Posts: 89



(Msg. 4) Posted: Wed Jan 23, 2008 3:06 am
Post subject: Re: Backing up from one table to another and adding date/time [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 23 Jan, 00:15, Kenoli wrote:
> On Jan 22, 1:00 pm, ZeldorBlat wrote:
>
>
>
> > On Jan 22, 3:29 pm, Kenoli wrote:
>
> > > I want to insert the data from one record in one table into another
> > > table in a mysql database, adding the current date and time to a field
> > > in the table the data is going into. Thus when a record is changed, I
> > > am backing it up and indicating the date and time of the backup in a
> > > "date" field.
>
> > > The following is the method for copying data from a field in one table
> > > to another.
>
> > > INSERT INTO tbl_2 (fld_1, fld_2) SELECT tbl_1.fld_1, tbl_1.fld_2 FROM
> > > tb_1 WHERE tbl_1.fld_id = [some record number];
>
> > > How can I mix this with adding the new date/time data to a date field
> > > in table 2 as well?
>
> > > Thanks,
>
> > > --Kenoli
>
> > Just include another column with the value of NOW():
>
> > INSERT INTO tbl_2 (fld_1, fld_2, fld_date)
> > SELECT tbl_1.fld_1, tbl_1.fld_2, NOW()
> > FROM tb_1
> > WHERE tbl_1.fld_id = [some record number];
>
> Thanks. I'll try it. And it won't get confused looking for a NOW()
> field in tbl_1?
>
> --Kenoli

http://dev.mysql.com/doc/refman/5.0/en/select.html
 >> Stay informed about: Backing up from one table to another and adding date/time .. 
Back to top
Login to vote
Kenoli

External


Since: Jan 22, 2008
Posts: 3



(Msg. 5) Posted: Wed Jan 23, 2008 10:36 am
Post subject: Re: Backing up from one table to another and adding date/time [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jan 23, 7:36 am, Ian Pawson wrote:
> Kenoli wrote:
> > I want to insert the data from one record in one table into another
> > table in a mysql database, adding the current date and time to a field
> > in the table the data is going into.  Thus when a record is changed, I
> > am backing it up and indicating the date and time of the backup in a
> > "date" field.
>
> > The following is the method for copying data from a field in one table
> > to another.
>
> > INSERT INTO tbl_2 (fld_1, fld_2) SELECT tbl_1.fld_1, tbl_1.fld_2 FROM
> > tb_1 WHERE tbl_1.fld_id = [some record number];
>
> > How can I mix this with adding the new date/time data to a date field
> > in table 2 as well?
>
> > Thanks,
>
> > --Kenoli
>
> There is a field type that does this automatically - it auto updates
> with the current_timestamp - have a look at TIMESTAMP

Thanks
 >> Stay informed about: Backing up from one table to another and adding date/time .. 
Back to top
Login to vote
Ian Pawson

External


Since: Dec 16, 2005
Posts: 5



(Msg. 6) Posted: Wed Jan 23, 2008 12:00 pm
Post subject: Re: Backing up from one table to another and adding date/time information [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Kenoli wrote:
> I want to insert the data from one record in one table into another
> table in a mysql database, adding the current date and time to a field
> in the table the data is going into. Thus when a record is changed, I
> am backing it up and indicating the date and time of the backup in a
> "date" field.
>
> The following is the method for copying data from a field in one table
> to another.
>
> INSERT INTO tbl_2 (fld_1, fld_2) SELECT tbl_1.fld_1, tbl_1.fld_2 FROM
> tb_1 WHERE tbl_1.fld_id = [some record number];
>
> How can I mix this with adding the new date/time data to a date field
> in table 2 as well?
>
> Thanks,
>
> --Kenoli
>
There is a field type that does this automatically - it auto updates
with the current_timestamp - have a look at TIMESTAMP
 >> Stay informed about: Backing up from one table to another and adding date/time .. 
Back to top
Login to vote
Display posts from previous:   
   Database Forums (Home) -> PHP SQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]