COMPUTER ENGINEER

Blog
SQL Server / T-SQL6 min study
03/ 65

Database foundations

Safe practice environment and sample data

Use one consistent dataset throughout the course.

UnderstandStudy an examplePractise

Understand the concept

The course uses common T-SQL features available in SQL Server 2019 and later. Version or compatibility requirements are identified in the relevant lessons. Run examples through SSMS on a local development instance and in the separate SqlStudioLab database. The website does not execute queries or connect to a production database.

Download the sample data script. It creates a new SqlStudioLab database and stops if that name already exists instead of deleting an existing lab. CREATE DATABASE permission is required; production application users should not receive that permission. Because the script contains GO separators, use a batch-aware client such as SSMS or sqlcmd.

The dataset contains six customers, seven products, twelve orders, eighteen order lines and five employees. It deliberately includes a customer without orders, an unsold product, NULL emails, tied salaries and multiple order statuses. Dates are fixed, so results do not change with today’s date. OrderItem.UnitPrice records the sale-time price; it need not match the product’s current Price.

WHEN TO USE IT

Use an isolated lab to make results repeatable, comparable and independent of production.

COMMON PITFALL

Do not run copied UPDATE or DDL examples in another database. Check DB_NAME() first.

01 / PRACTICE

One topic. Three levels of depth.

T-SQL / SQL Server 2019+
SELECT DB_NAME() AS DatabaseName;

The result should be SqlStudioLab. Select the correct database in SSMS if it is not.

This page does not execute SQL. Practise in the downloadable SqlStudioLab using SSMS. Before rerunning temporary-table examples, remove only the relevant #table. Views, procedures and functions create persistent lab objects; never use a production connection.

02 / YOUR TURN

Try it yourself first.

Check the lab tables and their row counts.

Show the solution and explanation
Worked solution
SELECT COUNT(*) AS OrderLineCount FROM lab.OrderItem;

There should be 18 rows. Changing the fixture changes later expected results.