How to view Stored Procedures in Squirrel - database

Would like to know if one can view stored proc is Squirrel. Is there a plugin for this?

What version of SQuirreL are you working on ?..
I have 3.2.1 and all I need to do is click on "Objects" tab, expand your connection, look for your database, expand it, and then look for "Procedure" then click on the procedure you want, and then click on the "Source" tab

You have to install your correspondent database plugin. In case of sqlserver, you can install it with squirrel-sql installation by checking Microsoft SQL-Server Plugin as per below:
.
So once installed, you can:
Right click on the stored procedure in the left menu,
Select sql server from the drop down menu,
Then select script procedure from the sub-menu
Here is a screenshot:

An easy way to get Stored Procedures source code on Ingres database:
select
procedure_name, text_sequence, text_segment
from
iiprocedures
where
procedure_name = 'sp_name_goes_here'
order by
text_sequence
Aloha!

Using SQuirreL 3.5.2, I knew there should be Procedures in our database but they were not showing by default. I right-clicked the Procedures and chose "Refresh Item" to get them to show. Must not be loaded by default so that can be misleading.

Related

Export multiple stored procedures to text files

In SQL Server Management Studio, I have a database with 200 stored procedures. I'm exporting each stored procedure as a script, by right clicking -> script stored procedure -> CREATE To -> File.
Is it possible to export all procedures at once, using a powershell script or anything else?
Use the Generate Scripts tool in SSMS:
Right Click Database in Object Explorer.
Tasks -> Generate Scripts.
If given the "tutorial" click Next.
Select "Select specific database objects" and tick "Stored Procedures". Click Next.
Choose export method. Likely here you want "Save as script file" with "one script file per object" selected. Ensure you choose the export location.
Click Next and Finish buttons as required.
If you are using MGT for MSSQL, then you follow these steps.
open MGT MSSQL and connect and open the list of databases
right button the the database where the stored procs are, this will open the con menu
go to "Tasks"
select "Generate Scripts"
select specific object, in your case, select "Stored Procedures" (you can select all or as you need)
then press "Next"
at the "Set Scripting Options" form, select the option; if you want all selected procs in one file or not, choose the directory where you want your files to be generated.
press "Next"
at the "Summary" form press "Next"
at the "Save or Publish Scripts" Press finish..
DONE.
There are advance options at step 7. to create each procs with drop and create option or just create options. go through those if you need.
tc.
I have developed a C# application that can accomplish this, scripting out all tables, views, stored procedures, functions, etc. to text files (one per object). This is very useful for scripting out the objects on a regular basis then keeping track of them in a Git repository. Download the DB Schema Export Tool from https://github.com/PNNL-Comp-Mass-Spec/DB-Schema-Export-Tool/releases
Example command line for automation:
DB_Schema_Export_Tool.exe
C:\Cached_DBSchema
/Server:Proteinseqs
/DBList:Manager_Control,Protein_Sequences
/Sync:"F:\Projects\Database_Schema\DMS"
/Git /Commit
/L /LogDir:Logs
/Data:ProteinSeqs_Data_Tables.txt
On Linux, use mono DB_Schema_Export_Tool.exe
Information on Mono
There are other command line switches available; see the Readme.
In addition to SQL Server, the software supports Postgres. Example output files can be found at https://github.com/PNNL-Comp-Mass-Spec/DBSchema_DMS/tree/master/DMS_Pipeline

Generate a "Create Table" script in Toad / SQL Navigator

I know that in SQL Server Management Studio you have the ability to right click on any table and are able to select Script Table As > CREATE To and are then able to get the entire create statement for any object in your DB.
Does anyone know if there's a similar functionality in Toad / SQL Navigator?
Although #Gary's answer above works in Toad, just for the sake of completeness, I wanted to mention that in SQL Navigator, I couldn't get it working as-is and, so, managed to do it using:
Extract DDL > Code Editor > SQL Scripts
Hope this helps someone else too..
In Toad, select your table in the object navigator then right-click and select "Create Script".
There are various options to select that control what is included in that script too.

How do I export my views from a database?

I have a number of views in my SQL Server database.
How do I export these as CREATE VIEW scripts?
I tried to right click the database - script database as - create to - new query editor window, but it doesn't show my my views (or tables even for that matter).
Any ideas?
In SSMS, if you right click the DB -> Tasks -> Generate Scripts... - that will take you through a wizard.
You can run through the wizard and select your DB, then the views as AdaTheDev mentioned or you can right click on each query and generate a script directly.
I prefer another way, because always I edit the views to remove "not necessary script generated SQL syntax" (depends on the point of view :)).
Right click the view, Generate script, CREATE in, new window.
See screenshot below (sorry for german version, but should work anyway).
I tried to right click the db - script database as - create to - new query editor window, but it doesn't show my my views (or tables even for that matter).
The purpose of the menu you mentioned is only to create the empty database, without any tables, views or anything else.
If you want to script anything beyond the empty database, you have to use the wizard already mentioned in AdaTheDev's answer.
Maybe you receive empty page because source of VIEW was encrypted or removed.
In older SQL editions there was a trick - after creating VIEW (SQL Server compiled it) developer could remove source of VIEW statement to protect it from "deassemblation". In current editions there is possibility to encrypt source of VIEW statement.

How do I remove database name from SQL Server generated script?

Anytime I use 'script table as' -> 'Insert To' (or other command), the script generated automatically places the database name in the script. Such as:
INSERT INTO [DatabaseName].[dbo].[tblToBeInserted] ...
While not a huge problem to just delete it, it has slipped by a few times and the script breaks if run on a different server with a different database name but has the same schema. (Such as running on [DatabaseName.Test])
Is there an option I can change, or can I modify the output in any way to remove this?
Assuming that you are using Microsoft SQL Server Management Studio 2005 or higher you can goto the Tools -> Options menu. On the dialog select "Scripting" from the left hand side. On the right-side in the "General Scripting Options" section there is an option called "SCRIPT USE ". You can set that to FALSE.
in SSMS 18.x, Go to the "Tools" menu and then select "Options". from the left side of the Options window select "SQL Server Object Explorer" and then "Scripting".
set "Script USE database" to False.
In SSMS, go to View -> Template Explorer, you can find a lot of templates there. Or, you can find these template .sql files from %appdata%\Microsoft\Microsoft SQL Server\100\Tools\Shell\Templates\Sql

Script all stored procedures in Management Studio 2005

In Enterprise Manager you could script all SPs in a database through the right click menu, is there a way to do it in Management Studio?
You can right click on the database and to go Tasks -> Generate Scripts...
This will allow you to script all or selected objects (schema, stored procedures, tables, users and views) with specific options.
Go to Microsoft SQL Server Management Studio
Select the database
Right click on selected database
Select 'Tasks'
Select 'Generate Scripts'
Select 'Next'
Select / tick 'Select specific database objects'
Tick 'Stored Procedures'
Select 'Next'
Select the option where do you want to save the file
Sure. All you need to do is to is click on the Stored Procedure in the Object Explorer and then highlight all the stored procedures in the Summary pane. Then simply right click and choose the scripting option that you prefer.
Good luck
Right click the database, choose Tasks, choose Generate Scripts.., click Next, Next again, choose Stored procedures, Next, Select All, Finish.
Presto!
If you right click on the database name, the bottom option is "Generate Scripts" which will then launch a wizard to generate scripts for the whole DB or specific objects inside.

Resources