Good Afternoon,
We are currently working on a tool, which retrieves all the Stored Procedures in a given database, which then extracts each Table being used in each Stored Procedure.
Currently, I got all of the Stored Procedures in a List, don't know if there are any parsers available that I can pass the Stored Procedure and returns the Tables being used.
The plan is then to link each Stored Procedure with the Tables being used in a Graph Database.
Thanks
I think there is no prewrited methods to get that. You have to request the database tables, then check in each stored procedure query if it contains the table name.
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
This query will return the tables in the database
Related
I have a requirement, where a stored procedure returns 2 results (has 2 select queries). I want to be able to read these 2 different tables at the same time.
How can I do so? Please advice
I need to pass a DataTable to the Oracle DB stored procedure to merge with an existing table, dynamically, from a c# function.
with Microsoft SQL database it's pretty easy, just create a UDT in the database that can match the DataTable column names and then I can use merge in the procedure.
I need to create the user-defined type dynamically and create a merge script dynamically given only the table name, the columns names and type, and the data.
is there a way to do so with Oracle?
I need to do the same with Microsoft SQL database: creating a dynamic user-defined type, using it with a merge procedure that was dynamically created.
just to be clear. the problem is making those merge dynamically, inside the C#.
I do not want to create a new procedure or a user-definded type inside the Oracle or Microsoft SQL databases.
I need to import around 100k records a few dozen times a day into an AWS hosted SQL Server Web 13.00.2164.0.v1
AWS doesn't support bulk insert, and SQL Server Web doesn't support SSIS.
I am reading records from a csv file with a C# console app, performing some data transformations and then inserting 1 record at a time with SqlCommand under a single transaction per 100k record file.
My current rate is around 25k records per 30 minutes, which seems ridiculously slow. I had originally developed this process using bulk inserts and could get 100k records inserted in about a minute. Is there anything I can do to speed this up?
The native way to do it is to use Table-Valued Parameters.
See also Table-Valued Parameters in .NET for explanations how to use them in your C# code.
So, create a stored procedure that accepts a table-valued parameter and pass all 100K rows in one call. You may try to experiment with the size of the batch and try smaller batches, but 100K is not too much.
In this stored procedure there will be a single INSERT statement that inserts rows from the parameter table into the permanent table.
It will be definitely faster than inserting one row at a time.
You have to convert your data in xml format and then transfer this xml data in to sql. Like bellow example
getting data from a dataset to xml format.
string objStr = ds.GetXml();//ds is a dataset object which contains table data
at database end:
CREATE PROCEDURE [dbo].[procedure name]
-- Add the parameters for the stored procedure here
#Val varchar(max) = null
AS
BEGIN
declare #xml xml
set #xml = convert(xml,#Val)
SELECT
T.Node.value('colname[1]', 'numeric(18, 2)') AS colname
FROM
#xmlValue.nodes('/NewDataSet/Table0') AS T(Node)
END
I have a stored procedure that is a class in my project. I gain the data returned by following:
EMTS.SPs.PrcEMTSDataLookup(so).GetDataSet().Tables[0].Copy()
This is placed in a dataset. The issue is the stored procedure has several selects and each select needs to be placed in a separate grid.
I have tried IDataReader and IDataAdapter but have not had any luck pulling data from the stored procedure object. I have research microsoft for information on IDataAdapter and the example they give uses SqlDataAdapter which is not necessary for me since the stored procedure is an object in the project.
So how do I get the different result sets in the sp and put them in separate grids?
For one of our recent projects, we created a stored procedure which generated SQL and executed it in the end. The purpose of the stored procedure was to create pivots based on dynamic columns.
When trying to access it using Entity Framework using the usual function import when I tried to access the stored procedure, it would return anything as it requires a dynamic type to store the retrieved data.
Which in our case was a dynamic query and linq was unable to get the returned columns. So to work around what I did was call the stored procedure in the traditional way i.e. creating a DataAdapter and SqlCommand object and SqlConnection object.
But what is the proper way of calling this kind of stored procedure using Entity Framework?
Thanks in advance.
Entity framework doesn't support dynamic result sets from stored procedures. It also doesn't support stored procedures using dynamic SQL because it cannot get static result set declaration from the procedure. So you must either ensure that your procedure will always return static type (same number of columns with same names) or you must use traditional ADO.NET to execute that procedure.
Following steps can be followed:
Store the dynamic part of SP inside a variable and the print that variable at end of the SP.
execute the SP and execute it with some data.
open the Messages tab in Result window.
copy the code that is written after (x row(s) affected);
paste that code in the SP and comment out everything else until variables declaration.
execute the new modified SP and add it to the entity framework. This time, entity framework will make a complex type which you want.
uncomment the previous commented code and delete the data that you copied from Messages tab and execute it again.
Follow the same process every time you add or remove columns from the SP.