Sybase system procedure - how to get result? - database

Is there any way of saving the result set of a SYSTEM procedure in Sybase ASE 15?
For example, if i want to get details about all the columns of a table, i would use the following code: sp_columns 'TABLE_NAME'.
I want to save the result into a temporary table or get it by using a cursor to use it for other queries. Is there any way of doing it?
Note: I am aware i could write my query by using the system tables and get the same result, but if this is possible, i would prefer this method.

The system stored procedures are not intended to be used for inputs into other tables/procedures.
If you don't want to write your own queries, you can look at the code behind the stored procedure by using sp_helptext. For system stored procedures you need to be in the sybsystemprocs db.
use sybsystemprocs
go
sp_helptext sp_columns
go
From there you can take a look at what is being queried and just grab what you need.
It's also helpful to take a look at the Sybase ASE System Tables Diagram: This shows all the system tables, and all the relationships between tables.

You can also use proxy tables to store the output of the SP in table.
This example is very helpful

Related

How to get the return of a sql server procedure on Pentaho?

I have a Pentaho transformation with three steps:
Table input. It works perfectly.
Execute SQL script, which I exec a sql server procedure. This procedure returns 4 tables, but I am not able to catch this three tables.
Text file output. Here I would like to save the contains of the before returned tables.
My main problem is that my partners have developed a procedure that returns some tables, when clearly this is a misunderstanding of the procedure concept. It should be a table valued function.
Despite this, I have to fix this someway, so, I am asking for advise. Anyone knows how to catch the tables?
Greetings.
I have tried this in the past and I believe it is not possible (although I can't seem to find the docs at the moment). Even if you could achieve this, how would you tell Pentaho what to do with each of the separate tables?
My solution at the time was to alter the proc so that only a single table was returned. Either by splitting the proc into several procs or combining the output into a single larger table with a parameter to split out in Pentaho.

How to perform cleaning operations on all tables in a database based on actions in a table

I am not sure how to word this, and it might be easy, but I have one table with a list of actions for several variables
Example of data:
Table=X
Variable=AccountNumber
Action=Set to blank (written in SQL code)
I want the code to go to X.accountnumber and perform action, and do this for all the table/variables combination in a particular database
I assume I will need dynamic SQL for this? I am just trying to figure out how to get started in doing a column by column search for each table and if the column matches, call the action from the action table
Any ideas?
I'd recommend using the undocumented stored procedure sp_msforeachtable.
See here for more info
Agree with #Jeffrey Van Laethem, more information here
sp_MSforeachtable

SQL - How to check if altering a table will break any stored procedures

Is there a nice way before I alter a table (e.g. remove a column), to see if that this will break any stored procedures?
I am trying to do this in MS SQL Server
Use the query here to search all stored procedures for the table and column name. You will probably still want to look at the code for each one you find to verify that it will or won't break.
you can use the following query to search for the table name in any stored procedures:
SELECT name
FROM sys.procedures
WHERE Object_definition(object_id) LIKE '%Your_Table_Name%'
I suggest you:
Make sure you have a separate environment (DEV)
Use the sample code from here to create a proc that confirms all objects in the database can be recompiled
How to Check all stored procedure is ok in sql server?
Use it - I can guarantee you will already have failing objects before you remove your column
Remove your column and use it again to see if more things broke
The more mature approach to this is to put your database into a database project and build that. But you can't do this until your database is valid.

Obtaining stored procedures information

I want to know information regarding stored procedures, such as who created the stored procedure, who is the author, and more.
I meant server wise, not definition from a book.
Use this query to view some of the stored procedure's metadata:
select * 
  from information_schema.routines 
 where routine_type = 'PROCEDURE'
Have a look at system tables such as sys.objects, they have information like creation date etc, may not have everything you are after though.
select *
from sys.procedures
I think you've got a problem if you need to know the author though.
You could set up auditing for the future, but right now you might need to do without the author info.

Mass change datatype and rename of dependent store procedure variables

I am in the process of optimising my database and I was thinking of changing the datatype for some columns from DATETIME to SMALLDATETIME on my tables.
Is there a system stored procedure that returns both the contents/code of a store procedure and the dependent table which will then allow me to do a join on a filtered list of tables?
Cheers!
EDIT1:
Im looking to programatically rename the stored procedures not track dependencies!
The built-in dependency tracking for SQL isn't very good for this type of work. Two tools come to mind thought...
Red Gate SQL Dependency Tracker - Good for determining all the dependent code
Visual Studio for Database Developers - Contains TSQL Code Analysis which can identify if a piece of data is being treated as an incorrect type.
Red Gate has a free trial on their stuff, which might get you through this job
I answered a simliar question to this (link below) with a sample of a scipt I use to find text in stored procedures (and functions and views). It requires a bit of work, but might help you here.
[How to find data table column reference in stored procedures
[1]: http://How to find data table column reference in stored procedures
If your dependencies in SQL Server are accurate, you can use sys.sql_dependencies with appropriate joins.

Resources