I'm using Oracle SQL Developer Version 4.1.2.20.
I expand the procedures folder, find the procedure I need to edit, and I right-click->Edit.
The procedure appears as one entire line, even though the procedure is multiple lines long.
Is there a view option to see the procedure with block structure with multiple lines?
Related
I am a new man for PostgresQL; working in DBEaver. I have created a procedure that modifies, among others, a temp table. I would like to print out the table for testing purposes: to see what is in the table now.
In T-SQL I could just execute “select * from MyTestTable”; and this was output to SQL Studio Grid tab. This did not break the procedure.
Now on Postgres I am using DBeaver and get errors when I try to use the same approach.
A question to experienced PostgresQL: how you cope with that? Is there any way to “peek my nose” into middle of a proc and see – what data are at given moment in table. If no - how to debug large and complicated procedures without ability to look at produced data Grid?
I have a data anonymization process that takes a production copy of a database and turns it into an anonymized copy by UPDATE-ing some columns.
Some of the tables contain several million rows so instead of UPDATE-ing the columns, which is very log intensive, I went down the way of
SELECT
Id,
CAST('Redacted' AS NVARCHAR(255)) [ColumnRequiringAnonymization]
INTO MyTable_New
FROM MyTable
EXEC sp_rename MyTable, MyTable_old
EXEC sp_rename MyTable_new, MyTable
DROP TABLE MyTable_old
The problem with this approach is that the "new" table no longer has any of the keys, indices and other dependent objects. I have figured out the keys and indices using SPs to generate the DROP and CREATE scripts. The SPs are based on manually written SQL as can be seen e.g. in this answer.
The next problem is that we have a schemabound view on top of this table, which has indices and a full-text index on its own. The number of SPs to generate scripts is growing and I am sure there will be mistakes.
Is there a way to completely script a table/view by using SQL commands only? ie. just like SSMS does when you click "Script table as - CREATE to" but within a stored procedure?
Right-click on the database, select Tasks; there is Generate Scripts there. Just follow prompts or Google for additional information.
I have many stored procedures. I need to see the query which is being executed.
Is there any way I can print the stored procedure like other MySQL queries ?
Right click on the stored procedure and use the Send To Editor or Send To Clipboard actions to get the create statement that was used to create the SP (similar for the other db objects).
Is there a stored procedure or some SQL that I could run that would display the SQL for creating a table from an existing table? Like sp_helptext to display the contents of a function or stored procedure. Basically, is there a way to do the Script Table As->CREATE TO method?
The answer is no. If you start profiler, and run [scirpt table]>[create to] in SSMS, then you'll see a series of sp_executesql being ran on sys.* tables. This means that no CREATE TABLE commands are stored anywhere in SQL server, and SSMS assemblies CREATE statements for a table from a lot of different sources.
On the other hand, if run [script view]>[create to], you'll see a simple query from sys.all_objects, sys.sql_modules, sys.system_sql_modules, where definitions are stored.
An SQL table has hundreds of tables, stored procedures and functions.
I am trying to put together an SQL query that will return all the dependencies of a given set of tables. Is there a way to accomplish this using SQL Server Management Studio without writing queries?
Updated: Simplified the question to the point.
In SSMS, just right click on the table and choose "View Dependencies". As far as scripting, take a look at this article.
EDIT: In SSMS, you can only see it for one. The reason why is because of the stored procedure that is run to view them only takes one database object. So to script multiple, you'd simply need to use multiple lines of EXEC sp_depends #objname = N'DATABASE.OBJECT'; for the tables/views/stored procedures/functions that you want to get dependencies for. One approach would be to use a script like the following to get the unique list of all dependent objects that will have to be included:
CREATE TABLE #dependents (obj_name nvarchar(255), obj_type nvarchar(255))
-- Do this for every primary object you're concerned with finding dependents for
INSERT INTO #dependents (obj_name, obj_type)
EXEC sp_depends #objname = N'DATABASE.OBJECT'
-- ...
SELECT DISTINCT obj_name, obj_type
FROM #dependents
DROP TABLE #dependents
I just blog something similar to this that might help:
Knowing What to Test When Changing a SQL Server Object.
Another approach would be to right click the database and select "Tasks" and then "Generate Scripts...", check the checkbox "Script all objects in the selected database". This will give you a giant text file that you can then search.