Click here to Skip to main content
Click here to Skip to main content

SQL Statement Generator

By , 14 Dec 2006
 

Sample Image - screen0.jpg

Introduction

The SQL Statement Generator is a Windows application that loads a DataTable from the specified query and then generates INSERT, UPDATE, or DELETE SQL statements based upon the type of SQL command and the selected columns of the DataTable.

Standard SQL queries can be specified to construct the precise DataTable of the data to generate the SQL statements for. Also, the name of the target table and the columns of the resultant generated SQL statements can be selected to contruct the exact SQL statements you want to generate.

Background

I'll admit it - I hate writing INSERT SQL statements, especially when it involves tables of more than three columns and two-three rows (a rarity...not!). I had a task that involved migrating data from a poorly-architected database to a new database, and later the data would need to be exported again to the production database after the development and testing phases were completed. Initially, this utility only handled INSERT statements, and then was expanded to also include UPDATE and DELETE SQL statements.

Using the Application

The SQL Statement Generator is quick and easy to use - just select the database and/or table/SQL query and the load the results into the grid. Then specify the type of SQL statement to generate and the columns to include in the SQL statements, click the GENERATE button, and voila! - instant SQL statements!

For INSERT statements, all the columns in the result-set are auto-selected by default, except for the zeroth column (since that is typically the primary key).

For UPDATE statements, all the columns in the result-set are auto-selected by default, except for the zeroth column (similar to the INSERT statements). However, the generation process for UPDATE statements has an added step - the WHERE column(s) for the resulting SQL statements need to be specified, because the identity value of the primary keys between the same two tables in different databases is usually different.

For DELETE statements, only the zeroth column in the result-set is auto-selected by default, since DELETEs typically use the primary key to identify which records to delete. Deleting rows by a complex WHERE clause is not always the safest method...

Note: The SQL Server to enumerate the databases and their tables from is specified in the configuration file, and you may need to leave off the Database/Initial Catalog attribute, since all the databases in the datasource/SQL Server are enumerated.

SQL Statement Generator Examples

INSERT Statements

insert

INSERT Results

insert-results

DELETE Statements and Results

deletes

UPDATE Statements

update-where

UPDATE Results

update-results

The SQL Statement Generator Engine - How It Works

The main engine/processor of the SQL Statement Generator is the SqlScriptGenerator class, which reads the columns of the DataTable and generates the SQL statements based upon the columns selected by the user. Once all the SQL statements are generated, they are dumped to a temp file and then displayed in a text editor (Notepad, by default).

public class SqlScriptGenerator
{
    public static string GenerateSqlInserts(ArrayList aryColumns, 
                                            DataTable dtTable, 
                                            string sTargetTableName)
    {
        string sSqlInserts = string.Empty;
        StringBuilder sbSqlStatements = new StringBuilder(string.Empty);

        // create the columns portion of the INSERT statement
        string sColumns = string.Empty;
        foreach (string colname in aryColumns)
        {
            if (sColumns != string.Empty)
                sColumns += ", ";

            sColumns += colname;
        }

        // loop thru each record of the datatable
        foreach (DataRow drow in dtTable.Rows)
        {
            // loop thru each column, and include
            // the value if the column is in the array
            string sValues = string.Empty;
            foreach (string col in aryColumns)
            {
                if (sValues != string.Empty)
                    sValues += ", ";

                // need to do a case to check the column-value types
                // (quote strings(check for dups first), convert bools)
                string sType = string.Empty;
                try
                {
                    sType = drow[col].GetType().ToString();
                    switch (sType.Trim().ToLower())
                    {
                        case "system.boolean":
                            sValues += (Convert.ToBoolean(drow[col]) 
                                        == true ? "1" : "0");
                            break;

                        case "system.string":
                            sValues += string.Format("'{0}'", 
                                       QuoteSQLString(drow[col]));
                            break;

                        case "system.datetime":
                            sValues += string.Format("'{0}'", 
                                       QuoteSQLString(drow[col]));
                            break;

                        default:
                            if (drow[col] == System.DBNull.Value)
                                sValues += "NULL";
                            else
                                sValues += Convert.ToString(drow[col]);
                            break;
                    }
                }
                catch
                {
                    sValues += string.Format("'{0}'", 
                               QuoteSQLString(drow[col]));
                }
            }

            //   INSERT INTO Tabs(Name) 
            //      VALUES('Referrals')
            // write the insert line out to the stringbuilder
            string snewsql = string.Format("INSERT INTO {0}({1}) ", 
                                            sTargetTableName, sColumns);
            sbSqlStatements.Append(snewsql);
            sbSqlStatements.AppendLine();
            sbSqlStatements.Append('\t');
            snewsql = string.Format("VALUES({0});", sValues);
            sbSqlStatements.Append(snewsql);
            sbSqlStatements.AppendLine();
            sbSqlStatements.AppendLine();
        }

        sSqlInserts = sbSqlStatements.ToString();
        return sSqlInserts;
    }

    public static string GenerateSqlUpdates(ArrayList aryColumns, 
                         ArrayList aryWhereColumns, 
                         DataTable dtTable, string sTargetTableName)
    {
        string sSqlUpdates = string.Empty;
        StringBuilder sbSqlStatements = new StringBuilder(string.Empty);

        // UPDATE table SET col1 = 3, col2 = 4 WHERE (select cols)
        // loop thru each record of the datatable
        foreach (DataRow drow in dtTable.Rows)
        {
            // VALUES clause:  loop thru each column, and include 
            // the value if the column is in the array
            string sValues = string.Empty;
            foreach (string col in aryColumns)
            {
                string sNewValue = col + " = ";
                if (sValues != string.Empty)
                    sValues += ", ";

                // need to do a case to check the column-value types 
                // (quote strings(check for dups first), convert bools)
                string sType = string.Empty;
                try
                {
                    sType = drow[col].GetType().ToString();
                    switch (sType.Trim().ToLower())
                    {
                        case "system.boolean":
                            sNewValue += (Convert.ToBoolean(drow[col]) ==
                                          true ? "1" : "0");
                            break;

                        case "system.string":
                            sNewValue += string.Format("'{0}'", 
                                         QuoteSQLString(drow[col]));
                            break;

                        case "system.datetime":
                            sNewValue += string.Format("'{0}'", 
                                         QuoteSQLString(drow[col]));
                            break;

                        default:
                            if (drow[col] == System.DBNull.Value)
                                sNewValue += "NULL";
                            else
                                sNewValue += Convert.ToString(drow[col]);
                            break;
                    }
                }
                catch
                {
                    sNewValue += string.Format("'{0}'", 
                                 QuoteSQLString(drow[col]));
                }

                sValues += sNewValue;
            }

            // WHERE clause: loop thru each column, and include
            // the value if column is in array
            string sWhereValues = string.Empty;
            foreach (string col in aryWhereColumns)
            {
                string sNewValue = col + " = ";
                if (sWhereValues != string.Empty)
                    sWhereValues += " AND ";

                // need to do a case to check the column-value types
                // (quote strings(check for dups first), convert bools)
                string sType = string.Empty;
                try
                {
                    sType = drow[col].GetType().ToString();
                    switch (sType.Trim().ToLower())
                    {
                        case "system.boolean":
                            sNewValue += (Convert.ToBoolean(drow[col]) == 
                                          true ? "1" : "0");
                            break;

                        case "system.string":
                            sNewValue += string.Format("'{0}'", 
                                         QuoteSQLString(drow[col]));
                            break;

                        case "system.datetime":
                            sNewValue += string.Format("'{0}'", 
                                         QuoteSQLString(drow[col]));
                            break;

                        default:
                            if (drow[col] == System.DBNull.Value)
                                sNewValue += "NULL";
                            else
                                sNewValue += Convert.ToString(drow[col]);
                            break;
                    }
                }
                catch
                {
                    sNewValue += string.Format("'{0}'", 
                                 QuoteSQLString(drow[col]));
                }

                sWhereValues += sNewValue;
            }

            // UPDATE table SET col1 = 3, col2 = 4 WHERE (select cols)
            // write the line out to the stringbuilder
            string snewsql = string.Format("UPDATE {0} SET {1} WHERE {2};", 
                                            sTargetTableName, sValues, 
                                            sWhereValues);
            sbSqlStatements.Append(snewsql);
            sbSqlStatements.AppendLine();
            sbSqlStatements.AppendLine();
        }

        sSqlUpdates = sbSqlStatements.ToString();
        return sSqlUpdates;
    }

    public static string GenerateSqlDeletes(ArrayList aryColumns, 
                                            DataTable dtTable, 
                                            string sTargetTableName)
    {
        string sSqlDeletes = string.Empty;
        StringBuilder sbSqlStatements = new StringBuilder(string.Empty);

        // loop thru each record of the datatable
        foreach (DataRow drow in dtTable.Rows)
        {
            // loop thru each column, and include 
            // the value if the column is in the array
            string sValues = string.Empty;
            foreach (string col in aryColumns)
            {
                string sNewValue = col + " = ";
                if (sValues != string.Empty)
                    sValues += " AND ";

                // need to do a case to check the column-value types
                // (quote strings(check for dups first), convert bools)
                string sType = string.Empty;
                try
                {
                    sType = drow[col].GetType().ToString();
                    switch (sType.Trim().ToLower())
                    {
                        case "system.boolean":
                            sNewValue += (Convert.ToBoolean(drow[col]) ==
                                          true ? "1" : "0");
                            break;

                        case "system.string":
                            sNewValue += string.Format("'{0}'", 
                                         QuoteSQLString(drow[col]));
                            break;

                        case "system.datetime":
                            sNewValue += string.Format("'{0}'", 
                                         QuoteSQLString(drow[col]));
                            break;

                        default:
                            if (drow[col] == System.DBNull.Value)
                                sNewValue += "NULL";
                            else
                                sNewValue += Convert.ToString(drow[col]);
                            break;
                    }
                }
                catch
                {
                    sNewValue += string.Format("'{0}'", 
                                 QuoteSQLString(drow[col]));
                }

                sValues += sNewValue;
            }

            // DELETE FROM table WHERE col1 = 3 AND col2 = '4'
            // write the line out to the stringbuilder
            string snewsql = string.Format("DELETE FROM {0} WHERE {1};", 
                                            sTargetTableName, sValues);
            sbSqlStatements.Append(snewsql);
            sbSqlStatements.AppendLine();
            sbSqlStatements.AppendLine();
        }

        sSqlDeletes = sbSqlStatements.ToString();
        return sSqlDeletes;
    }

    public static string QuoteSQLString(object ostr)
    {
        return ostr.ToString().Replace("'", "''");
    }
    
    public static string QuoteSQLString(string str)
    {
        return str.Replace("'", "''");
    }
}

Conclusion

I hope you find this article and utility useful - it has made working with SQL statements and data migration a snap! Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Chris Hambleton
Software Developer
United States United States
Member
SOFTWARE: Chris Hambleton is a Software Developer with proven experience in developing both web and Windows client-server applications with WPF, ASP.NET, C#, SQL Server, VB.NET, Visual C++, and VB6.
 
Chris's website is at ChrisHambleton.com and he has a small web-hosting/consulting business called CustomersInFocus.com. He has several other websites such as EzekielWatch.com, iWriterPro.com, and BookBlitzer.com.
 
WRITING: He has also written several fiction books ("The Time of Jacob's Trouble" and "Endeavor in Time"), available at CWHambleton.com and of course, at Amazon.com (Full Amazon Profile).

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberDaqdibi23 Mar '13 - 23:00 
Gave me new ideas.Thanks
GeneralMy vote of 5mvpKanasz Robert26 Sep '12 - 4:59 
Great job. Well done.
QuestionMy Vote of 5memberSaranRaj 2718 Aug '12 - 9:34 
Time saver , thank you !
Generalawsome- 10 points out of 10memberdarshan.pandya868 Aug '12 - 19:38 
awsome- 10 points out of 10 Thumbs Up | :thumbsup:
GeneralMy vote of 5memberVanlalruata Hnamte22 Jun '12 - 6:05 
I love it! It makes the query to be done easily.
 
If you could implement the Image query too, it would be nice!
GeneralWorking Like CharmmemberVanlalruata Hnamte22 Jun '12 - 6:04 
It works like charm. I am sharing the link in HackForums too.
 
Lovely! Wink | ;)
Vanlalruata Hnamte
- ZoSoft Network -

QuestionIt's WorkingmemberVanlalruata Hnamte22 Jun '12 - 6:02 
It's working perfectly. Nice tools. Thanks for your introduction! I love it.
 
I am giving you 5 out of 5 rating.
Vanlalruata Hnamte
- ZoSoft Network -

QuestionThanks! Saved me from RedGatememberRS Reddy220 Apr '12 - 12:31 
Cheers.
QuestionFix for Guid and Time fieldsmemberJacquers14 Mar '12 - 21:34 
Guid and time (timespan) types need to be enclosed in quotes. In the GenerateSqlInserts and GenerateSqlUpdates methods you can just add the following code:
 
case "system.guid":
case "system.string":
case "system.timespan":
sbValues.Append(string.Format("'{0}'", QuoteSQLString(drow[col])));
break;
 
and
 
case "system.guid":
case "system.string":
case "system.timespan":
sbNewValue.Append(string.Format("'{0}'", QuoteSQLString(drow[col])));
break;
Questionconsidering locale... [modified]memberroberto galbiati15 Dec '11 - 5:32 
hi
 
using on a Server installed in Italian, i got
 
INSERT INTO [Massimali]([IdTipoPratica], [IdSottoTipoPratica], [AnnoRiferimento], [Descrizione], [GiorniCarenzaTitolareRivendita], [GiorniCarenzaAltri], [GiorniInvioDocumentazione], [PercentualeFranchigia], [ImportoMinimoFranchigia], [ImportoMassimoDocumento], [NumeroMassimoDocumenti], [ImportoMassimoPratica], [ImportoMassimoAnnuale], [DataCreazione], [UtenteCreazione], [DataModifica], [UtenteModifica])
    VALUES(2, 2, 2012, 'Annuo', 30, 30, 300, 10,00, 0,0000, 0,0000, 0, 0,0000, 40000,0000, NULL, NULL, NULL, NULL);
 
instead of
 
INSERT INTO [Massimali]([IdTipoPratica], [IdSottoTipoPratica], [AnnoRiferimento], [Descrizione], [GiorniCarenzaTitolareRivendita], [GiorniCarenzaAltri], [GiorniInvioDocumentazione], [PercentualeFranchigia], [ImportoMinimoFranchigia], [ImportoMassimoDocumento], [NumeroMassimoDocumenti], [ImportoMassimoPratica], [ImportoMassimoAnnuale], [DataCreazione], [UtenteCreazione], [DataModifica], [UtenteModifica])
    VALUES(2, 2, 2012, 'Annuo', 30, 30, 60, 10.00, 0.0000, 0.0000, 0, 0.0000, 40000.0000, NULL, NULL, NULL, NULL);
 

comma is decimal separator in Italy, but SQL command should be invariant...
i used :
 
default:
                                if (drow[col] == System.DBNull.Value)
                                    sbValues.Append("NULL");
                                else
                                    sbValues.Append(Convert.ToString(drow[col], CultureInfo.InvariantCulture));
                                break;
 

 
tks
roberto
 

UPD: the same for date

modified 15 Dec '11 - 12:04.

GeneralHi Vote 5 out of 5memberRohit_kakria15 May '11 - 5:00 
Thanks for providing this. It was very useful tool when I was transferring a website database in new designed normalized database.
 
Thanks,
Rohit
moderator (http://xpode.com)
GeneralGreat Tool!memberMS86TO18 Feb '11 - 9:14 
This is exactly what I was looking for.
 
I did find a little problem, when it comes to GUID values. After generating the script, I found that not all GUID values had the single quote around it, which is needed to successfully run in sql server. I quickly made the change in the code myself in a few minutes and now it works fine. So, if you want, you can add "system.guid" system type with the same as string.
 
Anyway, thanks for this!
GeneralMy vote of 4memberJacquers15 Feb '11 - 21:48 
Very useful app, thanks! Just needs a fix for handling Guid / uniqueidentifier types (missing the quotes '').
GeneralMy vote of 5memberruanmyv20 Oct '10 - 5:59 
Great article!
Generalgood programmemberJessie_blue_camote25 Jul '10 - 2:02 
nice program, this help me a lot on my task.
 
Regards..
GeneralNicememberMuneer Abdullah1 Jul '10 - 2:35 
Nice Work!
GeneralAwesome tool. Many thanks!!!memberJacktheRipper7 Jun '10 - 0:08 
Wow! I was just searching the web for a way to generate SQL INSERT statements in SSMS 2005 Express and look at what I found (or what found me). Within moments of downloading the program, I was off generating INSERT statements for my database. Thanks a lot! Many blessings to you! Cheers! Big Grin | :-D
GeneralThank you for the ideamemberHunty18 Feb '10 - 6:07 
Hello Chris
I came accross your post when I was developing a tool for generating SQL statement. Your system wasn't the exact thing I was looking for, but it did point me to the right direction. I really appericate for your help.I hope you don't mind if I take some of your ideas and massaged it into this another thing I am developing.
 
Thanks
GeneralRe: Thank you for the ideamemberChris Hambleton18 Feb '10 - 7:22 
That's fine - glad it was helpful!
GeneralYou got 5 out of 5memberRohit_kakria10 Feb '10 - 0:18 
Hi,
 
Thanks for efforts. It saved my a lot of time..... Smile | :)
 
----
Rohit
GeneralRe: You got 5 out of 5memberChris Hambleton10 Feb '10 - 1:45 
You're welcome! It helps me be much more productive (or at least look like I am).. Smile | :)
GeneralRe: You got 5 out of 5memberRohit_kakria15 May '11 - 5:01 
Cheers Smile | :)
GeneralNot workingmembersavedtech4 Feb '10 - 5:05 
When I open the porgram I get an error telling me tables can not be loaded? What do I do? Thank you.
GeneralRe: Not workingmemberChris Hambleton4 Feb '10 - 5:13 
You probably just need to set the connection string in the config file. If that doesn't work, you may need to check/set your permissions on the database.
GeneralGenerate guid fields with the ' behind the fieldmemberthomvandermeulen9 Oct '09 - 20:56 
Hello Chris,
 
Thanks for your excelent sql statement generator.
 
I have one little problem with the generator. When I generate the insert script there are no "'" signs around de the guid fields.
I have to place them by hand.
 
Is it possible that guid fiels are automaticly surrounded by the ' ?
 
Regards,
 
Thom van der Meulen
GeneralRe: Generate guid fields with the ' behind the fieldmemberChris Hambleton10 Oct '09 - 6:38 
Hi Thom - thanks for your email. I'll put in a fix for this as soon as I get a free moment (which are few these days). However, since the source is available, you should be able to modify it yourself without much trouble.
 
In the SqlScriptGenerator.cs file, insert the following code in the switch statement (more or less) and then recompile and debug:
 
case "system.guid":
sbValues.Append(string.Format("'{0}'", QuoteSQLString(drow[col])));
break;
 
Hope this helps!
 
Chris
GeneralThanks - you really saved my timememberashok_sole17 Dec '08 - 7:55 
Thanks - you really saved my time
GeneralI am about to write something like this and I found your post!memberMember 165968810 Dec '08 - 15:07 
Good WORK Chris!
GeneralYou Rock Chrismemberblubandoo6 Nov '08 - 13:09 
You saved me so much of time, You rock Chris!!!
 
Lee

GeneralRe: You Rock ChrismemberChris Hambleton6 Nov '08 - 13:17 
thanks!
QuestionNice work men!memberLeleHalfon5 Mar '07 - 3:02 
I'm converting this articule to ASP.NET
Do you already have it ?
AnswerRe: Nice work men!memberChris Hambleton5 Mar '07 - 3:30 
Not yet - go for it! It would be nice to have one that uses ajax too... Smile | :)
GeneralRe: Nice work men!memberLeleHalfon5 Mar '07 - 8:15 
I want to add the functionally for connect to different`s server.
Do you know the "SQL-DMO.dll" ??
Why you didn`t use it ?
GeneralFeature request: support for multiple serversmembervincebowdren18 Dec '06 - 4:12 
I'm using this app on two different servers, and although the app quite happily connects to either and will work on either, it could do so a little more cleanly. Suggestions, starting with the simplest/easiest:
1) State which server the app is connected to - e.g. in the title bar?
2) Allow the user to specify multiple servers in the config file, and allow them to choose one on startup to connect to.
3) Allow the user to specify multiple servers in the config file, and allow them to switch between them while the app is running.
 
Vince
My opinions should not be as confused as those of my employers
GeneralCode/Demo app UpdatedmemberChris Hambleton16 Dec '06 - 17:55 
The code has been updated with most of the changes/enhancements suggested since the initial posting. The only change that wasn't added was the ability to browse tables/databases from a non-default schema (something other than 'dbo'.
 
During my testing, I was able to browse two different databases/tables that were of a schema other than dbo and it worked fine. What could be an issue is that the schema is not included in the statements that are generated, and this will probably be left for another enhancement...
 
Cheers!
GeneralRe: Code/Demo app Updatedmembervincebowdren18 Dec '06 - 4:00 
Cheers, seems to be working fine so far.
 
Vince
My opinions should not be as confused as those of my employers
Generaltics: Need to be converted to double-ticsmemberdarrin.wolf14 Dec '06 - 13:43 
Yo,
 
I wrote a perl to do this stuff. Ever since I wrote it, I've found that I need to constantly tweak it to do yet another slightly more complex task. Heh. Anywho... I briefly glanced accross your code and don't see that you handle embedded tics in STRING data. STRING (varchar, etc.) data like this:
column name |column type |column data
fullname |varchar(40) |O'Reiley
 
When you generate an INSERT for this data, the generated text may likely look like:
'O'Reiley'
 
This will cause T-SQL errors. The correct INSERT text needs to have all (inner) tics doubled. The first tic acts as a metacharacter switch, for the second tic.
'O''Reiley'
 
Just FYI, sorry if you already covered this, I cannot compile your solution because I only have VS .NET 2003 installed (for work) on my machine, and this version complains that the sln was created with a newer version and dies. Frown | :-(
 
-Darrin

GeneralRe: tics: Need to be converted to double-ticsmembervincebowdren14 Dec '06 - 22:30 
It already does this; I've been using the app in anger for the past couple of weeks now, and I definitely would have posted about it if it wasn't escaping the single-quotes.
 
Vince
My opinions should not be as confused as those of my employers
GeneralReserved words as field namesmembervincebowdren7 Dec '06 - 8:37 
If a fieldname is a reserved word, the sql which is generated doesn't escape it:
     INSERT INTO MyTable(MyID, MyDesc, Group) VALUES (7, 'foo', 'bar')
So mssql gets confused:
     Incorrect syntax near the keyword 'Group'.
 
I think the recommended thing to do is to escape them with square brackets thus:
     INSERT INTO MyTable(MyID, MyDesc, [Group]) VALUES (7, 'foo', 'bar')
 
That's what query analyser does when it generates sql for you, anyway. I think you can happily use double-quotes to the same effect.
 
Vince
My opinions should not be as confused as those of my employers
GeneralRe: Reserved words as field namesmemberPhreud14 Dec '06 - 13:53 
Careful here. Is that an extended MS SQL feature or ANSI SQL? I hate it when my INSERTS only work in MS SQL Server, but bomb if I need to move data to an oracle or informix database. Frown | :-(
GeneralInternational date formatsmembervincebowdren7 Dec '06 - 1:12 
Where it generates sql with a date, I think it needs to specify the date in an unambiguous format, to cope with internationalisation issues. I'm working in the UK, and it is generating sql statements with date formats thus:
INSERT INTO AmsClinicStreamFrozen (ClinicDate) VALUES ('14/12/2006 00:00:00')
Now 14/12/2006 (14th December) is the date I was after, but when I try and run this query mssql returns this error:
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."
This could be avoided by stating dates in an unambiguous format, for example:
INSERT INTO AmsClinicStreamFrozen (ClinicDate) VALUES ('14 December 2006 00:00:00')

 
Vince
GeneralRe: International date formatsmemberChris Hambleton7 Dec '06 - 8:04 
Good catch - I'll include this in the next update; probably something like 'yyyy-MM-dd hh:mm:ss'
GeneralWhy notmembericestatue5 Dec '06 - 11:24 
Why not use NHibernate or some other opensource applications that model Meta-data mapper enterprise design patterns.Hmmm | :|
 
nothing

GeneralRe: Why notmemberChris Hambleton7 Dec '06 - 8:06 
I'll check it out - I hadn't heard of NHibernate before.
GeneralDbCommandBuildermemberzeleps5 Dec '06 - 9:05 
Have you ever seen DbCommandBuilder? It does exactly the same thing...
GeneralRe: DbCommandBuildermemberChris Hambleton7 Dec '06 - 8:21 
I have seen DbCommandBuilder, and have used it in other projects. The approach of this SQL Statement Generator was to act upon any DataTable (even datatables that came from and XML file) and dump the SQL to a text file, and not just transfer data between two databases.
 
In several companies I've worked for, we had to dump and then tweek large amounts of SQL statements from one database to another, and have a paper/source trail of the changes made. In those circumstances/constraints, using the DbCommandBuilder to transfer directly between two databases was not really an option. However, it could be used to just create all the SQL commands and have them dumped to a text file...
 
Thanks for your input!

GeneralMissing support for binary datamemberthomas_z4 Dec '06 - 8:46 
Hi,
 
Look great, congratulation!
 
I found an issue about binary data, you'll generate the following statement:
INSERT INTO Categories(CategoryName, Description, Picture)
VALUES('Beverages', 'Soft drinks, coffees, teas, beers, and ales', System.Byte[]);
 
Regards,
Thomas
GeneralRe: Missing support for binary datamemberChris Hambleton4 Dec '06 - 10:21 
Yeah -- I'll admit that binary data is not handled very well! I'll check into a solution when I get the time and update the code with the rest of the suggestions... Smile | :)
GeneralNot working for table owners/schemas other than dbomemberVistaPista4 Dec '06 - 6:50 
Try it with a table
 
mySchema.Customers
 
...
GeneralRe: Not working for table owners/schemas other than dbomemberChris Hambleton7 Dec '06 - 8:22 
Ouch - I'll check into where/how to handle different schemas...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 14 Dec 2006
Article Copyright 2006 by Chris Hambleton
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid