Sql-Server

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.

2025-03-24

SQL Interview: 30 Temporary 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: Administration Level: Advanced Question: Your session is connected to a database named PublicWorks. You want to create a temporary stored procedure, that only lasts until your session has ended. It should be available to all other sessions while your session is still active.

2025-03-23

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.

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.

2025-03-18

T-SQL 101: 131 What are Identity Columns in SQL Server?

In the previous post, I talked about how you could add default values for columns. One special type of default value is called an IDENTITY constraint. These columns are one way to achieve automatic numbering in a column. There are many pros and cons about using these but at this point, I want to make sure you know how to use them. The main difference from other columns is that you don’t put them in your INSERT statements.

2025-03-18

SQL Interview: 27 Copy only backups 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: Administration Level: Intro Question: You need to take an additional backup copy of a database to send to another site. You are considering using the Copy Only backup option. What exactly is different about a Copy Only backup, compared to a Full backup?

2025-03-17

T-SQL 101: 130 What are Default Constraints in T-SQL?

Default constraints allow us to automatically provide values for columns when: we don’t supply them ourselves they are marked as NOT NULL so they are required When you’re building an INSERT statement, you don’t have to give values for all columns. Columns that are declared as NULL aren’t mandatory, so you don’t have to supply those columns at all. Those columns can just be NULL. But if you have a column that is declared as NOT NULL, so it requires a value, but you haven’t supplied it in the INSERT statement, then a default constraint can provide the value.

2025-03-16