473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Trigger for creating csv of new data

I'd like to create a trigger to export to csv the new data added to the table. I've written:

Expand|Select|Wrap|Line Numbers
  1. delimiter |
  2. create trigger trg_customer_csv after insert on customers
  3. for each row
  4. begin
  5. select new.account_code into outfile 'e:/trigfile.csv'
  6. fields terminated by ';'
  7. lines terminated by '\n' 
  8. from customers;
  9. end;
  10. |
this exports the new data once for every record in the table, so I got a csv with the new account_code 361 times.

I also really wanted to export all of the data, so have tried select new.* but nothing exported at all.

Any help would be appreciated.
Mar 1 '13 #1
1 4947
Luuk
1,047 Expert 1GB
"I also really wanted to export all of the data, so have tried select new.* but nothing exported at all."
replace line 5 with:
Expand|Select|Wrap|Line Numbers
  1. select * into outfile 'e:/trigfile.csv'
This should export all the data in the table (providing the outputfile does not exist)

or, if you just want the complete last record:
Expand|Select|Wrap|Line Numbers
  1. select * 
  2. into outfile '/tmp/trigfile.csv'
  3. fields terminated by ';'
  4. lines terminated by '\n' 
  5. from customers
  6. where account_code=new.account_code;
  7. end;
Mar 3 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Artco News | last post by:
Hi, I was wondering if any of you experts has some example of MySQL data entry form either using PHP or any public domain software for my photo album. I'd like to enter some description with it. ...
16
by: chudson007 | last post by:
I have a table, TableA with amongst other fields, a field for Qty. Qty can range from 0 to 100. How do I count the number of rows with a qty between 1 and 10, 11 and 20, 21 and 30, and so on using...
0
by: Mark Lewin | last post by:
Hi all I'm pulling my hair out over this particular problem and I'm wondering whether you clever people can help. I'm running the demo version of Access 2003, which I understand to be a...
1
by: alex n | last post by:
hello. i'm trying to implement IBindingList to wrap DataTable (like DataView) with hierarchy capabilities and bind it to DataGrid. The problem is i don't know yet all the stuff i need to know....
0
by: simon | last post by:
I have: par1 = New SqlParameter("@mediaId", SqlDbType.VarChar, 10) par1.Value = "text" myParams.Add(par1) par2 = New SqlParameter("@datumStart", SqlDbType.DateTime) par2.Value = Now()...
2
by: asad | last post by:
hello, how ru all pls tell me how can i create DAL and how can i use it in my ASP.NET pages thanks
1
by: YouTube | last post by:
Hi All, Can anyone help with this problem: I have designed the tables, created the relationships etc, since this morning, when when I go to view the relationships there is nothing there. When I...
2
by: danceli | last post by:
I have made trigger on table 'FER' that would be fired if data is inserted, updated to the table. And also, I made batch file using bcp to extract the newly updated / inserted records. But I got...
8
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all, How can i add or delete some columns from datareport at runtime. How can i refresh datareport at runtime. How can i format fields at runtime How can i cjange the datastring or...
2
by: sentenza | last post by:
I want to create a function that 'on update' and 'on insert' in table A column nome_tabella create another table named as the record just added in A: CREATE FUNCTION trig_creazione_tabella()...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.