|
Comments and Discussions
|
 |
 |
As another developer who's written a number of IT productivity tools over the years, I really appreciate this one. I noticed the comment from another user about RedGate--yup, I installed that too and it caused problems with my SSMS (Secret Santa Management Studio?).
Thanks for doing it.
|
|
|
|
|
|
|
 |
awsome- 10 points out of 10
|
|
|
|
 |
I love it! It makes the query to be done easily.
If you could implement the Image query too, it would be nice!
|
|
|
|
 |
It works like charm. I am sharing the link in HackForums too.
Lovely!
Vanlalruata Hnamte
- ZoSoft Network -
|
|
|
|
 |
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 -
|
|
|
|
|
 |
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;
|
|
|
|
 |
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:04pm.
|
|
|
|
 |
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)
|
|
|
|
 |
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!
|
|
|
|
 |
Very useful app, thanks! Just needs a fix for handling Guid / uniqueidentifier types (missing the quotes '').
|
|
|
|
|
 |
nice program, this help me a lot on my task.
Regards..
|
|
|
|
|
 |
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!
|
|
|
|
 |
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
|
|
|
|
 |
That's fine - glad it was helpful!
|
|
|
|
 |
Hi,
Thanks for efforts. It saved my a lot of time.....
----
Rohit
|
|
|
|
 |
You're welcome! It helps me be much more productive (or at least look like I am)..
|
|
|
|
 |
Cheers
|
|
|
|
 |
When I open the porgram I get an error telling me tables can not be loaded? What do I do? Thank you.
|
|
|
|
 |
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.
|
|
|
|
 |
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
|
|
|
|
 |
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
|
|
|
|
 |
Thanks - you really saved my time
|
|
|
|
|
 |
You saved me so much of time, You rock Chris!!!
Lee
|
|
|
|
|
 |
I'm converting this articule to ASP.NET
Do you already have it ?
|
|
|
|
 |
Not yet - go for it! It would be nice to have one that uses ajax too...
|
|
|
|
 |
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 ?
|
|
|
|
 |
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
|
|
|
|
 |
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!
|
|
|
|
 |
Cheers, seems to be working fine so far.
Vince
My opinions should not be as confused as those of my employers
|
|
|
|
 |
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.
-Darrin
|
|
|
|
 |
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
|
|
|
|
 |
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
|
|
|
|
 |
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.
|
|
|
|
 |
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
|
|
|
|
 |
Good catch - I'll include this in the next update; probably something like 'yyyy-MM-dd hh:mm:ss'
|
|
|
|
 |
Why not use NHibernate or some other opensource applications that model Meta-data mapper enterprise design patterns.
nothing
|
|
|
|
 |
I'll check it out - I hadn't heard of NHibernate before.
|
|
|
|
 |
Have you ever seen DbCommandBuilder? It does exactly the same thing...
|
|
|
|
 |
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!
|
|
|
|
 |
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
|
|
|
|
 |
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...
|
|
|
|
 |
Try it with a table
mySchema.Customers
...
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
First Posted | 1 Dec 2006 |
Views | 143,570 |
Bookmarked | 130 times |
|
|