Tag Archives: sql server

SQL Server: list all user defined functions in a database

Recently I inherited a database project where many of the functions were not listed nor documented. Thankfully, with the help of the always useful stackoverflow, I was able to find the following snippet for displaying all user functions: select name, definition, type_desc FROM sys.sql_modules m INNER JOIN sys.objects o ON m.object_id=o.object_id where type_desc like ‘%function%’ via sql server – SQL list of all the user defined functions in a database – Stack Overflow. Very cool! 🙂

Format SQL code

I have been writing copious quantities of SQL lately. Some of the queries are getting really long. When I am working with Navicat it has a nice ‘SQL beautify’ feature that takes messy SQL and makes it nice and tidy. 🙂 While that features is great when using Navicat for SQL editing, sometimes I need to workdirectly with SQL Server 2008 there is no comparable feature built into Microsoft’s SQL pane. 🙁 Thankfully, with a quick copy/paste there is an online tool

Select top 2 rows from records, grouped/partitioned by Unique ID

The Problem: A client needed a query that selected the two most recent tour dates for each user ID. This is an easy task for a single user ID because specifying the user ID and an ORDER BY tour_date DESC with a LIMIT 2 clause would get the dates needed. However, when there are a lot of users it gets harder. For a single date, the MAX function works great but in our instance it will not work because we

SQL Server database and table listing

I generally work with MySQL, not MS SQL Server. So when I needed some basic automated info about a SQL Server’s database/table layout I was thankful for the following two pages: Get list of databases from Sql Server – Stack Overflowhttp://stackoverflow.com/questions/147659/get-list-of-databases-from-sql-serverHow can I get the list of available databases on a SQL server instance? I’m planning to make a list of them in a combo box in vb.net. Get a list of all database on a SQL Server: SELECT name