Hey all! Welcome to, or welcome back, to SQL Something!
Today we're taking a quick look at how to list all Stored Procedures (and Functions) in a database. As per usual, I needed to do this at some point for my job and so I'm sharing what I found. :-)
In order to get the information we need we will be querying information_schema.routines as follows:
SELECT ROUTINE_NAME as 'Stored Procedure',
ROUTINE_CATALOG as 'Database Name',
ROUTINE_SCHEMA as 'Database Schema',
ROUTINE_TYPE as 'Object Type (PROCEDURE/FUNCTION)',
ROUTINE_DEFINITION as 'Stored Procedure Definition',
CREATED as 'Date Created',
LAST_ALTERED as 'Date Last Altered'
FROM information_schema.routines with (nolock)
WHERE ROUTINE_TYPE = 'PROCEDURE'
ORDER BY ROUTINE_NAME
The above will list all Store Procedures for the database that you run the query on. Very helpful! :-)
Now you'll notice the WHERE clause specifies the PROCEDURE type only. If we wanted info on Functions as well as Stored Procedures, we can remove this clause.
If we wanted info on Functions only and wanted some additional info like what value the Function returns, we tweak the query as follows:
SELECT ROUTINE_NAME as 'Function Name',
ROUTINE_CATALOG as 'Database Name',
ROUTINE_SCHEMA as 'Database Schema',
ROUTINE_TYPE as 'Object Type (PROCEDURE/FUNCTION)',
ROUTINE_DEFINITION as 'Function Definition',
DATA_TYPE as 'Return Value Type',
CREATED as 'Date Created',
LAST_ALTERED as 'Date Last Altered'
FROM information_schema.routines with (nolock)
WHERE ROUTINE_TYPE = 'FUNCTION'
ORDER BY ROUTINE_NAME
DATA_TYPE returns the data type of the Function's return value or it returns TABLE if it's a table valued function.
DISCLAIMER: As stated, I’m not an expert so please, PLEASE feel free to
politely correct or comment as you see fit. Your feedback is always
welcomed. :-)
Monday, 16 February 2015
Sunday, 18 January 2015
Mini Post: Each GROUP BY expression must contain at least one column that is not an outer reference
Good day and welcome back to SQL Something!
I'm ashamed at how long I've been away and there is really no excuse. It is, however, a new year (2015 people!), so I'm going to try to be much better. Here's hoping!
We'll start this year with a very simple error that you may see when running a query:
"Each GROUP BY expression must contain at least one column that is not an outer reference"
The error itself is a bit vague, but refers to something quite simple. As the above error indicates, a "Group By" is involved. Maybe your query involves a variable like so:
SELECT COUNT([Column1]) AS TotalCount, [Column2], @Variable as VariableName
FROM [Schema1].[Table1]
WHERE [Column2] = @Variable
GROUP BY [Column2], @Variable;
Do you know what's wrong? It's the variable in the GROUP BY clause.
Normally, when using GROUP BY, you are required to put all the columns in the SELECT clause that are not part of a aggregate function into the GROUP BY clause. Following that logic you should also put any local variables that you are using in the SELECT clause. This however is not so.
Removing the variable like so fixes the query:
SELECT COUNT([Column1]) AS TotalCount, [Column2], @Variable as VariableName
FROM [Schema1].[Table1]
WHERE [Column2] = @Variable
GROUP BY [Column2];
Thank you, as usual, for your time. :-)
DISCLAIMER: As stated, I’m not an expert so please, PLEASE feel free to politely correct or comment as you see fit. Your feedback is always welcomed. :-)
I'm ashamed at how long I've been away and there is really no excuse. It is, however, a new year (2015 people!), so I'm going to try to be much better. Here's hoping!
We'll start this year with a very simple error that you may see when running a query:
"Each GROUP BY expression must contain at least one column that is not an outer reference"
The error itself is a bit vague, but refers to something quite simple. As the above error indicates, a "Group By" is involved. Maybe your query involves a variable like so:
SELECT COUNT([Column1]) AS TotalCount, [Column2], @Variable as VariableName
FROM [Schema1].[Table1]
WHERE [Column2] = @Variable
GROUP BY [Column2], @Variable;
Do you know what's wrong? It's the variable in the GROUP BY clause.
Normally, when using GROUP BY, you are required to put all the columns in the SELECT clause that are not part of a aggregate function into the GROUP BY clause. Following that logic you should also put any local variables that you are using in the SELECT clause. This however is not so.
Removing the variable like so fixes the query:
SELECT COUNT([Column1]) AS TotalCount, [Column2], @Variable as VariableName
FROM [Schema1].[Table1]
WHERE [Column2] = @Variable
GROUP BY [Column2];
Thank you, as usual, for your time. :-)
DISCLAIMER: As stated, I’m not an expert so please, PLEASE feel free to politely correct or comment as you see fit. Your feedback is always welcomed. :-)
Friday, 18 July 2014
Mini Post: Error 0xc02020a1: Data conversion failed. The data conversion for column returned status value 4
Helloooo! And welcome (or welcome back) to SQL Something!
Today's mini-post is about an error you can run into when attempting to use the Import/Export Wizard to import some data into a DB of your choice:
Today's mini-post is about an error you can run into when attempting to use the Import/Export Wizard to import some data into a DB of your choice:
Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "COLUMN NAME" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".
| Fig. 1: Annoying Error. |
Thursday, 17 July 2014
Error: The Server Instance Witness Rejected Configure Request
Hey everyone out there! Welcome back to SQL Something!
Today we look at an interesting problem. I'm not sure as to the root cause of it, but we will look at how to solve it.
(P.S. If anyone out there knows why this occurred, please feel free to contribute in the comments below)
The error in question is:
I discovered this error repeating continuously in the Application Log in the Windows Event Viewer.
Naturally I checked all the databases currently being mirrored, however all seemed to be in order (both the Principals as well as the Mirrors). So how can we find out more about the issue and how can we fix it?
Today we look at an interesting problem. I'm not sure as to the root cause of it, but we will look at how to solve it.
(P.S. If anyone out there knows why this occurred, please feel free to contribute in the comments below)
The error in question is:
The server instance Witness rejected configure request; read its error log file for more information. The reason 1427, and state 31, can be of use for diagnostics by Microsoft. This is a transient error hence retrying the request is likely to succeed. Correct the cause if any and retry.
| Fig. 1: So it begins. |
I discovered this error repeating continuously in the Application Log in the Windows Event Viewer.
Naturally I checked all the databases currently being mirrored, however all seemed to be in order (both the Principals as well as the Mirrors). So how can we find out more about the issue and how can we fix it?
Monday, 30 June 2014
Mini Post: Creating and Configuring a UDL file
Good day everyone! And welcome back to SQL Something!
Here I am at the end of the month again, trying to fit in a couple last minute posts. Said I wouldn't do this again. Hopefully I spread them out a bit better next month.
Anyway, without any more delay let's look at creating a UDL file.
Firstly a UDL (Universal Data Link) file allows persons to test connectivity to OLE DB Providers. The OLE DB Provider we are interested in, of course, is the one for SQL Server. This is very useful to quickly test credentials on a machine that does not have SQL Server Management Studio installed, but needs access to a SQL Server instance (example testing SQL Server access from an application server to a SQL Server).
Here I am at the end of the month again, trying to fit in a couple last minute posts. Said I wouldn't do this again. Hopefully I spread them out a bit better next month.
Anyway, without any more delay let's look at creating a UDL file.
Firstly a UDL (Universal Data Link) file allows persons to test connectivity to OLE DB Providers. The OLE DB Provider we are interested in, of course, is the one for SQL Server. This is very useful to quickly test credentials on a machine that does not have SQL Server Management Studio installed, but needs access to a SQL Server instance (example testing SQL Server access from an application server to a SQL Server).
Saturday, 31 May 2014
Mini Post: DTUTIL.exe
Hey everyone! Welcome back to SQL Something!
Let's see if we can get a couple posts in on the last day of the month.
In the next few posts we're gonna take a brief look at some of the command prompt utilities that get installed when you install Integrated Services (IS). These utilities are 32-bit unless you also install Client Tools or Data Tools.
The first of which is here (DTEXEC.exe).
The second of which is DTUTIL.exe.
DTUTL.exe is a command prompt utility used to manage SSIS packages. DTUTIL allows you to COPY, MOVE, DELETE or verify if a package EXISTs. The utility can be used on packages stored in:
(You designate the package location via the location options: /SQL, /DTS, /FILE respectively)
Syntax is as follows: DTUTIL /OPTION[Value] [/OPTION[Value]...]
Example: DTUTIL /SQL PackageName /DELETE
The above example calls the utility and tells it to delete the package named 'PackageName' in a SQL Server DB.
There are several parameters for the utility, but we'll just look at a few key ones below:
When copying to a SQL Server DB, sometimes credentials are required. For this you can use the below optional parameters:
DISCLAIMER: As stated, I’m not an expert so please, PLEASE feel free to politely correct or comment as you see fit. Your feedback is always welcomed. :-)
Let's see if we can get a couple posts in on the last day of the month.
In the next few posts we're gonna take a brief look at some of the command prompt utilities that get installed when you install Integrated Services (IS). These utilities are 32-bit unless you also install Client Tools or Data Tools.
The first of which is here (DTEXEC.exe).
The second of which is DTUTIL.exe.
DTUTL.exe is a command prompt utility used to manage SSIS packages. DTUTIL allows you to COPY, MOVE, DELETE or verify if a package EXISTs. The utility can be used on packages stored in:
- A SQL Server DB
- A SSIS Package Store
- The File System
(You designate the package location via the location options: /SQL, /DTS, /FILE respectively)
Syntax is as follows: DTUTIL /OPTION[Value] [/OPTION[Value]...]
Example: DTUTIL /SQL PackageName /DELETE
The above example calls the utility and tells it to delete the package named 'PackageName' in a SQL Server DB.
There are several parameters for the utility, but we'll just look at a few key ones below:
- /COPY - allows you to copy a package to a designated location.
- /DELETE - allows you to delete apackage in a designated location.
- /EXISTS - verifies that a package exists in a designated location.
- /MOVE - moves a package from a designation source to a designated destination.
When copying to a SQL Server DB, sometimes credentials are required. For this you can use the below optional parameters:
- /SOURCEU - Source Username
- /DESTU - Destination Username
- /SOURCEP - Source Password
- /DESTP - Destination Password
DISCLAIMER: As stated, I’m not an expert so please, PLEASE feel free to politely correct or comment as you see fit. Your feedback is always welcomed. :-)
Mini Post: DTEXEC.exe
Hey everyone! Welcome back to SQL Something!
Let's see if we can get a couple posts in on the last day of the month.
In the next few posts we're gonna take a brief look at some of the command prompt utilities that get installed when you install Integrated Services (IS). These utilities are 32-bit unless you also install Client Tools or Data Tools.
The first of which is DTEXEC.exe.
DTEXEC.exe is a command prompt utility that is used to configure and execute SSIS packages.
Configure:
Execution:
Actual execution is done by calling three stored procedures.
You can view examples of syntax here.
DISCLAIMER: As stated, I’m not an expert so please, PLEASE feel free to politely correct or comment as you see fit. Your feedback is always welcomed. :-)
Let's see if we can get a couple posts in on the last day of the month.
In the next few posts we're gonna take a brief look at some of the command prompt utilities that get installed when you install Integrated Services (IS). These utilities are 32-bit unless you also install Client Tools or Data Tools.
The first of which is DTEXEC.exe.
DTEXEC.exe is a command prompt utility that is used to configure and execute SSIS packages.
Configure:
- It let's you load packages from SQL Server, A SSIS package store and the File System.
- It let's you access package configurations which include: Parameters, Variables, Properties and Logging.
Execution:
Actual execution is done by calling three stored procedures.
- CATALOG.CREATE_EXECUTION - Creates an instance of execution in the SSIS catalog.
- CATALOG.SET_EXECUTION_PARAMETER_VALUE - Sets parameter values.
- CATALOG.START_EXECUTION - Starts an instance of execution.
You can view examples of syntax here.
DISCLAIMER: As stated, I’m not an expert so please, PLEASE feel free to politely correct or comment as you see fit. Your feedback is always welcomed. :-)
Subscribe to:
Posts (Atom)