Generare automaticamente l'SQL di INSERT per n record esistenti

lunedì, 28 gennaio 2008 23.19 by Marco Bellinaso

Qualche giorno fa ho avuto per l'ennesima volta la necessità di duplicare sul DB remoto di produzione n record che avevo creato sul DB locale di sviluppo di un sito. Sebbene sia possibile tramite gli strumenti di SQL Server esportare dei dati dal DB locale ed importarli direttamente in uno remoto, o sia comunque possibile esportare i dati in formato CSV importandoli poi altrove, l'opzione che ho sempre preferito (perlomeno nel caso abbia solo bisogno di replicare altrove n record da un'unica tabella, senza dover mantenere ID e integrità referenziale con altre tabelle) è di creare automaticamente un file con tanti statement INSERT quanti sono i record da copiare. Questa opzione è perfetta anche nel caso in cui la vostra applicazione sia venduta come pacchetto che il cliente si installa in casa, e abbiate bisogno di creargli gli script per auto-popolare il suo DB con dei dati di test, o comunque dei dati di base - non occorrerà infatti spiegargli procedure più o meno complesse per importare i dati da un file csv o da un DB remoto raggiungibile online...basterà solo fargli aprire il file .sql tramite il Query Analyzer, e farlo eseguire sul DB di destinazione.

Lo strumento che uso io è SQL Scripter, tool gratuito sviluppato tra l'altro con VB2005. E' molto ricco di opzioni, e permette ad esempio di specificare i campi da includere nella INSERT, i filtri condizionali (WHERE) che identificano i record per cui generare le INSERT (utile se voglio esportare solo i record inseriti negli ultimi n giorni, o solo quelli che fanno riferimento ad una certa categoria), la tabella di destinazione, l'utilizzo di transazioni ecc.

Correntemente valutato 4.3 da 3 utenti

  • Currently 4,333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Segnala:  
Tags:   ,
Categorie:   Sviluppo software
Azioni:   E-mail | Permalink | Commenti (11) | RSS CommentiRSS comment feed

Post correlati

Commenti

agosto 8. 2008 11.00

Raffaele

Di un utilità grandissima, purtoppo ora a pagamento. :-(

Ciao

Raffaele

gennaio 11. 2010 11.39

dentist plano

The airline business has always had a rich sense of humor, and one purportedly true story doing the rounds at the moment upholds the tradition. It concerns a stormy flight aboard a Boeing aircraft; an off-duty airline stewardess is sitting next to a man in the grip of serious white-knuckle fever as he watches, through his porthole, the aircraft's wing bending and bouncing in the tempest.

The stewardess tries to reassure him; she works in the industry and flies all the time, she tells him. There is nothing to worry about; "the pilots have everything under control."

"Madam," he replies, "I am a Boeing engineer and we did not design this aircraft to do what it is doing.



Regards
Camel

dentist plano

gennaio 19. 2010 10.56

small dog car seat

My Parents had not been out together in quite some time.

One Saturday, as Mom was finishing the dinner dishes, my father stepped up behind her.

"Would you like to go out, girl?" he asked.

Not even turning around, my mother quickly replied, "Oh, yes, I'd love to!"

They had a wonderful evening, and it wasn't until the end of it that Dad confessed.

His question had actually been directed to the family dog, lying near Mom's feet on the kitchen floor.


Regards
Hall

small dog car seat

marzo 5. 2010 09.45

personalized lanyards

Do you react guest posts? I would copulate to make unify articles here.

Regards
Parker





personalized lanyards

marzo 9. 2010 10.52

replica watches

thanks for the share

replica watches

marzo 22. 2010 15.02

ssk sorgulama

This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.

ssk sorgulama

marzo 23. 2010 16.18

ehliyet

Aw, this was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate alot and never seem to get something done.

ehliyet

marzo 24. 2010 14.46

rolex replica

thank you

rolex replica

marzo 25. 2010 14.52

bağkur

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post

bağkur

marzo 29. 2010 21.32

arac sorgulama

I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!

arac sorgulama

aprile 8. 2010 16.07

gerdek gecesi

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post

gerdek gecesi

Commenti chiusi