Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Copy row from one table to another on update or delete
Old 08-15-2009, 04:22 PM Copy row from one table to another on update or delete
Junior Talker

Posts: 2
Name: KA Hodges
Trades: 0
I'm trying to copy the contents of one table to another whenever there is a deleted or updated row, and then remove the updated row from the originating table. I have two tables identical, one for active employees, and one for terminated employees. I need to do this with php, as triggers are not an option on this shared host. I have the script protected with a .htaccess blocking all IP's except for mine. I'm not that versed on php and could use some help. Here's the schema of the tables. One is called active_employees and the other is called termed_employees:

Code:
id_employees int(10) Not Null 
payroll_no varchar(10) NULL 
employee_name varchar(75) NULL 
Sex varchar(7) NULL 
nextel varchar(13) NULL 
ssNumber varchar(13) NULL 
BirthDate varchar(30) NULL 
Hire_Date varchar(30) NULL 
QuitDate varchar(30) NULL 
PayRate varchar(8) NULL 
street_address varchar(100) NULL 
City varchar(50) NULL 
state varchar(25) NULL 
zip_code varchar(10) NULL 
home_phone varchar(15) NULL 
cellphonenum varchar(15) NULL


What I'd like to do is whenever a value for QuitDate is entered into the active_employee table, it copies the entire row to the termed_employees table, and remove the row from the active_employees table. Or, before a row is deleted in the active_employees table, it exports a copy of the row to the termed_employees table. This way there is always an archived copy of the terminated or accidently deleted employees data on the database.

Thanks in advance.
kahodges is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-15-2009, 04:42 PM Re: Copy row from one table to another on update or delete
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I don't think there is a copy operation in SQL. Why not just first select the data from the employee table using the employee's ID whom are being deleted, insert the data into your other table and then run the deletion query.
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to Copy row from one table to another on update or delete
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09969 seconds with 12 queries