Azure-Sql-Db

SQL Interview: 32 Using ALTER FUNCTION 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: Medium

Question:

You have a scalar T-SQL function in SQL Server and want to change it.

Apart from permissions, what would stop you from using ALTER FUNCTION to change it?

Answer:

You can’t change from an inline function to a multi-statement function.

2025-03-29

T-SQL 101: 136 Deleting Rows from a SQL Server Table

The DELETE statement is one of the most common SQL statements. We use it to remove rows from a table.

In the example, I’ve said to delete rows from the dbo.CinemaGroups table where the value in the CinemaGroupID column is greater than 3.

You need to make sure that your DELETE statements have WHERE clauses, unless what you’re intending to do is delete all the rows in the table. You don’t want to make the common mistake where people highlight a DELETE statement in SQL Server Management Studio and forget to include the WHERE clause as well.

2025-03-28

T-SQL 101: 135 What is a Foreign Key Constraint in SQL Server?

Foreign keys are mostly used where you store the primary key of another table, and want to check that it’s valid. This is used to ensure database integrity.

For example, I might have a CustomerID stored in an Orders table, and I want to make sure that the customer already exists. In the example above, I have a Courses table and I want to make sure that the CollegeID that’s stored for each course, actually matches a college that’s already in the Colleges table. I check that the CollegeID already exists by declaring a foreign key reference to that table.

2025-03-26

SQL Interview: 31 Create a copy of an Azure SQL Database on the same logical 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: Administration Level: Intro

Question:

You have an Azure SQL Database.

How can you create a copy of the Azure SQL Database on the same logical server?

Answer:

The easiest option is to use the CREATE DATABASE AS COPY OF command.

2025-03-25

T-SQL 101: 134 What is a Unique Constraint in SQL Server?

In the previous post, I talked about check constraints. Another type of constraint in SQL Server is a unique constraint.

What I want to specify is that a value in a column is unique i.e., no other row has that same value in that column. While a check of the values can be manually requested, the constraint is normally checked when SQL Server is inserting or updating the row.

It is also possible to specify a unique constraint at the table level, rather than at the column level. You might want a combination of columns to be unique. Single column unique constraints can be declared at either the column or the table level.

2025-03-24

T-SQL 101: 133 What is a Check Constraint in SQL Server?

I previously described how column data types help define what you can put in a column. But sometimes I need to be more specific.

For example, if I have an ExternalCourseRating column and it’s an integer but it’s not allowed to be any value outside the range 1 to 4, I need to do more than just say it’s an integer because that could have a wide range of potential values.

2025-03-22

SQL Interview: 29 Add column to middle of SQL Server table

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 need to add a new column to a table.

A developer insists that the column needs to be inserted into the middle of the existing table, not as a new column at the end.

2025-03-21

T-SQL 101: 132 Identifying the Last Value Inserted with Identity Columns in SQL Server

I showed how identity columns are a special type of constraint. They can be  int or bigint. Both work just fine. What you might need to know though, is the last value inserted automatically by SQL Server.

@@IDENTITY

For a long time, SQL Server only had a single option for this. It was the @@IDENTITY value.

The problem was that it could give you a value different to what you were looking for. The most common situation where this happened is if a trigger was set up. An INSERT trigger says when somebody does an insert, after it’s finished, execute this command as well. But what if that code in the trigger inserted a row somewhere else, perhaps to audit the inserts. The problem is that @@IDENTITY would return back the value from the second INSERT, not the one that you thought it was returning.

2025-03-20

SQL Interview: 28 When computed columns are calculated 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: Medium

Question:

You add a computed column to an existing table.

You then select from the table.

When is the value of the computed column calculated i.e., when the value is inserted or updated, or when the value is selected?

2025-03-19

SQL Server Administration for Developers and DBAs - new online on-demand course now available!

One of the most popular courses that we used to run in person was a SQL Server Administration course. Yesterday, I recently finished converting the course to an online format, and it was a big job.

I’ve had many people asking if we had this type of course. Administration is such an important skill.

Not just a single version course

We were also determined to stay with our tradition of making multi-version courses. We won’t just teach you about SQL Server 2022. Even though we’ve updated content to that version, we’ve included content for all relevant previous versions, and we show the progression across the versions.

2025-03-18