T-SQL 101: 128 Inserting Data into a Table using SQL Server T-SQL

To insert new rows into a table, you will mostly use the INSERT statement. In the example above, I’ve inserted one row into the dbo.CinemaGroups table. There are a few aspects to this statement. First, you should always use two-part names for the table i.e., use dbo.CinemaGroups not just CinemaGroups. Second, there is an optional INTO keyword for INSERT statements. You can say INSERT INTO dbo.CinemaGroups. While I’m generally pretty pedantic about these things, I can’t see any value that the word INTO adds here and I don’t use it.

2025-03-12

SQL Interview 25: Extended Stored Procedures in SQL Server

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database. Section: Development Level: Advanced Question: You are reviewing stored procedures in the master database. You note both Stored Procedures, and Extended Stored Procedures. What is the difference between these types of procedures? Answer: Stored Procedures are written in T-SQL or SQL CLR and run in the standard user memory space of a SQL Server session.

2025-03-11

T-SQL 101: 127 Querying the SQL Server System Catalog

There are times that you need to be able to query the database and its internal structures rather than querying the user tables. In the example above, I’ve asked for details of all the databases, and then for details of all the schemas in the current database, followed by details for all the tables and columns in the current database. These are a well-designed set of system views that are easy to work with.

2025-03-10

SDU Tools: List User-Defined Data Types in SQL Server

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. I do a lot of reviewing of database designs and one thing I always check for is the use of user-defined data types. I’ve had situations where these have caused me substantial issues. So we added a tool that can help to find these. It’s called ListUserDefinedDataTypes. The procedure takes one parameter.

2025-03-09

T-SQL 101: 126 Executing Dynamic SQL Statements in SQL Server T-SQL

It’s also possible to create the command dynamically before you execute it. In the example above, I’ve set a number of different parts of a SQL statement into variables, and then used them to construct a complete SQL statement that I’ve then executed. I just have to create a valid SQL statement as a string. Warning While this might seem really, really convenient, and it can be incredibly useful, it is something you need to be extraordinarily careful with.

2025-03-08

SQL Interview 24: DROP and CREATE vs ALTER for T-SQL Functions

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database. Section: Development Level: Medium Question: You are writing a script to change the code in a T-SQL function. You can choose to either DROP IF EXISTS and CREATE the procedure, or to use an ALTER statement. What advantage would you get from using an ALTER statement?

2025-03-07

T-SQL 101: 125 Executing Stored Procedures in SQL Server Using T-SQL

In T-SQL, the way we execute a stored procedure is to use the EXECUTE statement. We can write it as EXECUTE or as EXEC. You’ll almost always see it written as EXEC. In the first example above, I’ve executed a stored procedure called dbo.GetCinemaChanges. Note that I’ve included the dbo schema in the name of the procedure. For procedures like this, you should always include the schema name. The procedure also takes one parameter called @CurrentDate and set it to the 28th February 2012.

2025-03-06

Calculating sales volume in food wholesaling systems

In a previous post, I described the issues with measuring quantities in warehousing systems. I showed how you could well need to measure more than just quantities purchased or sold. You often need to deal with the hierarchies of containers that goods are supplied in. But while food wholesale systems will need to deal with quantities like I described in that post, they often have another layer of complexity. Items are often sold by:

2025-03-05

T-SQL 101: 124 Understanding Stored Procedures in SQL Server T-SQL

Stored procedures are prepackaged groups of T-SQL statements. They can also be written in other languages, but most of the time they’ll be written in T-SQL. There are pros and cons with using stored procedures. In the example shown, I use the EXEC statement to execute a stored procedure called SDU_Tools.ListAllDataTypesInUse. Parameters The procedure also takes a number of parameters. By using different parameters values, I can change the behaviour of the stored procedure.

2025-03-04

Cosmos Down Under show 15 with guest Saranya Sriram from the Cosmos DB team discussing AI and vector search is now released!

I really enjoyed recording another new Cosmos Down Under podcast this afternoon. It’s now edited and released. Show 15 features Saranya Sriram from the Azure Cosmos DB team. In the show, we discussed the AI and vector search capabilities in Azure Cosmos DB. About Saranya Saranya is the Asia product lead, and a principal product manager on the engineering team for Azure Cosmos DB, the database that powers OpenAI’s Chat GPT and similar AI-related workloads.

2025-03-03