Results 1 to 3 of 3

Thread: Some way/tool to do this with database scripts backups

  1. #1
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Question Some way/tool to do this with database scripts backups

    Hello guys

    if i have for example
    a simple table call person

    with 'id' and 'name' how columns

    i can do a backup and get some file (A.sql)
    with all the inserts statements

    here, all fine

    but
    how i can do this?

    for each insert statement generated in A.sql
    create a new B.sql, with update statements

    its possible do this?

    even worst, if a have a table with 20 columns
    i need the way to generate the same B.sql
    but with my desired columns to update

    thanks in advanced
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  2. #2
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    What would you expect the update statements to look like? They would need to have a unique column value in each row to key off of...
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  3. #3
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    hello pmularien

    let me explain me more

    think a table how this case

    cliente is customer/client in english

    Code:
     Field             Type         Null     Key     Default     Extra    
     ----------------  -----------  -------  ------  ----------  -------- 
     idCliente         varchar(11)  NO       PRI                          
     razonCliente      varchar(80)  NO                                    
     direccionCliente  varchar(80)  NO                                    
     rucCliente        varchar(11)  NO                                    
     dniCliente        varchar(9)   NO                                    
     telefonoCliente   varchar(15)  NO                                    
     celularCliente    varchar(10)  NO                                    
     emailCliente      varchar(50)  NO                                    
     fechaNacimiento   date         NO                                    
     ciudad            varchar(20)  NO
    ok
    i would have 1 to N rows already inserted in the db,

    and i can do a simple backup with some script/administration tool for any database
    (mysql/postgresql)


    for instance A.sql
    which would has this content

    Code:
    INSERT INTO `cliente` (`idCliente`,`razonCliente`,`direccionCliente`,`rucCliente`,`dniCliente`,`telefonoCliente`,`celularCliente`,`emailCliente`,`fechaNacimiento`,`ciudad`) VALUES 
     ('000273999','JOZEP E. VAN DEN OUWELAND','JIRON CONDE DE LEMOS # 226 - PUNO','','000273999','','','','2008-02-15','PUNO'),
     ('00454507','ALBERTO JESUS MARTIN LAZO FERNANDEZ','URB. SEŅORIAL H-4 CAYMA - AREQUIPA','','00454507','','','','2008-01-29','AREQUIPA'),
     .....
    the point is that table cliente has how you can see 10 columns for each insertion written by the backup

    the problem and my requirement is create a new sql file (called B.sql)

    with this content

    Code:
    UPDATE cliente SET razonCliente='JOZEP E. VAN DEN OUWELAND', ciudad='PUNO' WHERE idCliente='000273999'
    UPDATE cliente SET razonCliente='ALBERTO JESUS MARTIN LAZO FERNANDEZ', ciudad='AREQUIPA' WHERE idCliente='00454507'
    .....
    so for each INSERT statement createad in A.sql i need generate a UPDATE statement in B.sql
    with the columns that i want to update, in this case
    razonCliente, ciudad

    why i need create a B.sql?,
    the reason is to have a batch with a lot UPDATE staments,
    so i can open the file and edit some row and a specific column that i need

    for instance
    Code:
    UPDATE cliente SET razonCliente='JOZEP E. VAN DEN OUWELAND', ciudad='OTHER CITY' WHERE idCliente='000273999'
    UPDATE cliente SET razonCliente='I HAVE A NEW NAME', ciudad='AREQUIPA' WHERE idCliente='00454507'
    .....
    maybe i would need create a C.sql
    in this way
    Code:
    UPDATE cliente SET ciudad='PUNO' WHERE idCliente='000273999'
    UPDATE cliente SET ciudad='AREQUIPA' WHERE idCliente='00454507'
    .....
    to only have the option to edit the column ciudad for some row

    i hope you see my point now

    thanks in advanced
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •