Execute script from MySQL workbench EER model? - mysql-workbench

There's a facility in MySQL Workbench's EER Modelling mode to write an SQL script that's stored with the model. But I've looked all over the place and can't see any way of executing such a script, other than by copying and pasting it into a window of the query mode. There's a menu item Scripting/Run Script, but it doesn't seem to actually do anything. Surely there must be some application of the scripts section of the model beyond just storing SQL text?

Running arbitrary SQL code during forward engineering or synchronization is not possible. The only code that gets executed is the sql to create the objects and to fill tables with data specified in the Inserts section of the table editor.
Running an sql script in general is of course possible and also trivial. Simply open a connection to your server (you should have one created on the home screen, if not do this first). Then in the editor toolbar there's a button to open a script. Use that to open the file (if you have a separate sql file). If you want to run code that is stored in the model (as SQL file) you have to copy/paste it over.

Related

How to export executed statements from Oracle SQLDeveloper?

There is a statements logging in Oracle SQLDeveloper:
Is there any way to export them as plain text or log them to file?
UPD: The reason I want to collect statements to file is for easy diff (to compare expected vs truncated export). I have a schema which export is not completely performed by 'Tools -> Database export'. Indexes, constraints, packages and synonyms are missing in resulting file while they are obviously present in database and visible in SQLDeveloper.
No, just copy and paste.
You could always do a client based jdbc trace or a database session trace if you wanted that to go to a file.

Extract Active Directory into SQL database using VBScript

I have written a VBScript to extract data from Active Directory into a record set. I'm now wondering what the most efficient way is to transfer the data into a SQL database.
I'm torn between;
Writing it to an excel file then firing an SSIS package to import it or...
Within the VBScript, iterating through the dataset in memory and submitting 3000+ INSERT commands to the SQL database
Would the latter option result in 3000+ round trips communicating with the database and therefore be the slower of the two options?
Sending an insert row by row is always the slowest option. This is what is known as Row by Agonizing Row or RBAR. You should avoid that if possible and take advantage of set based operations.
Your other option, writing to an intermediate file is a good option, I agree with #Remou in the comments that you should probably pick CSV rather than Excel if you are going to choose this option.
I would propose a third option. You already have the design in VB contained in your VBscript. You should be able to convert this easily to a script component in SSIS. Create an SSIS package, add a DataFlow task, add a Script Component (as a datasource {example here}) to the flow, write your fields out to the output buffer, and then add a sql destination and save yourself the step of writing to an intermediate file. This is also more secure, as you don't have your AD data on disk in plaintext anywhere during the process.
You don't mention how often this will run or if you have to run it within a certain time window, so it isn't clear that performance is even an issue here. "Slow" doesn't mean anything by itself: a process that runs for 30 minutes can be perfectly acceptable if the time window is one hour.
Just write the simplest, most maintainable code you can to get the job done and go from there. If it runs in an acceptable amount of time then you're done. If it doesn't, then at least you have a clean, functioning solution that you can profile and optimize.
If you already have it in a dataset and if it's SQL Server 2008+ create a user defined table type and send the whole dataset in as an atomic unit.
And if you go the SSIS route, I have a post covering Active Directory as an SSIS Data Source

t-sql result into a file

I have spent few hours searching with no luck today.
What I need to do is to write a t-sql query which will be executed from within SSMS and which supposed save an output to a file.
I have full admin access to the sql server 2008 r2 as well as to the OS (I believe Win 2008 Server)
I cannot use commandline, batch files etc.
It needs to be done straight from SSMS as an execution of a t-sql script.
It doesn't even have to be pretty :-)
It just needs to do the job.
I would very appreciate any help.
Regards
Mariusz
Query > Results To > Results to File
You can also do a select all on the results pane, and right click the top-left cell. There's an option to "Save Results As," which will allow you save the results in CSV format.
If you're looking for something more advanced, I would suggest looking into SSIS (SQL Server Integration Services), which is the replacement for DTS. This is what's usually used for data file exports (DFEs)
EDIT
If you need to export the results to file via script, try this:
INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=c:\Test.xls;','SELECT productid, price FROM dbo.product')
I can think of two options, given your constraints
BCP would be the best option, use it with the queryout option I spaced on bcp being a command line utility.
Create a sql agent job that has a single step which is an OS command. THe job has a single step which runs a sqlcmd which runs the query and redirects the output to a file. After creating the job, the script runs it and then deletes the job and any history. That is a blecherous solution that would delight Rube Goldberg but would satisfy the requirements of being done completely through SSMS/automated approach.
If you're within SSMS the option to output to a text file is one of the "Results to ..." options on the toolbar alongside the execute button. Are you trying to something more programmatic?
If you have permission to execute xp_commandshell from SSMS you may be able to take advantage of some of the techniques suggested by the psuedonymous Phil Factor at http://www.simple-talk.com/sql/t-sql-programming/the-tsql-of-text-files/.

How can I see the call tree for SQL stored procedures offline (without actually creating them)

I have a huge SQL script which i need to analyse. It would be really helpful if i could find a way which can generate a call tree; ie, to see which all procedures are called from a particular procedure. a perl based example is here, http://sqlblog.com/blogs/linchi_shea/archive/2009/10/23/find-the-complete-call-tree-for-a-stored-procedure.aspx
but i need a tool to analyse the text file (.sql file), not the procedure stored in the database. due to some reasons i will not be able to create the whole set of procedures in the database and use the above mentioned tool.
please respond if you have come across any ide/tool with this feature.
Probably not very helpful, as it violates your request for a "offline" sql file, text based parsing tool, but wanted to throw this redgate tool out there that I have used with great success in the past; RedGate Sql Dependency Tracker. It works very well and does a good job mapping out your objects and all their dependencies (definable as to what you want mapped). But it does require a database with all of the existing objects in place to work properly. :(
If you can't find one out there, I guess you could maybe do some script/macro text parsing if all the procedure calls are easily defined and predictable in the file. AutoHotKey is a great general purpose scripting tool/framework, and there are a few sql based scripts out there...just not one exactly like you are looking for that I have seen.

A plugin like "Resharper" for SQL Server Management Studio?

Does anybody know of a program or plugin for SQL Server Management Studio which is like Resharper for MS Visual Studio?
For example, it would be great to enter Ctrl-Shift-N and after starting to enter the name of a stored procedure to see list of stored procedures with most general commands like - alter, drop and create.
Look at the ApexSQL refactor, it is FREE amazing add-in for Visual Studio and SQL Management Studio. http://www.apexsql.com/sql_tools_refactor.aspx
You can try SQL Prompt by redgate
I came across another interesting plugin called SqlSmash. It works with SSMS 2012 and is free for now it looks like.
Features from the website:
Go To Object: Easily navigate to any of the tables, stored procedures, functions or triggers in any of your databases.
Format Sql: Apply your casing preferences to the keywords, variables and identifiers and indent the Sql.
Execute Current Query: Only execute the query that your cursor is placed at.
Search Objects: Search all your database objects for any text.
Summarize Script: Summarize complex scripts and navigate around easily.
Go To Definition: Show the definition of a Sql object quickly.
Find All References: Find what other objects are referencing the Sql Object under your cursor.
Quick Info: Get a quick overview about the Sql Object under your cursor.
I don't think it has that autocomplete feature you've mentioned (which is in MS Management Studio >= 2008) but the "SSMS Tools Pack" add-in has some other features you might be interested in:
http://www.ssmstoolspack.com/
Features:
SQL Snippets
Window Connection Coloring
Window Content History, Query Execution History and Current Window History
Format SQL
Search Table, View or Database Data
Run one script on multiple databases
Copy execution plan bitmaps to clipboard or file
Search Results in Grid Mode
Generate Insert statements from resultsets, tables or database
Regions and Debug sections
Running custom scripts from Object Explorer
CRUD stored procedure generation
New query template
General options