Database foundations
Safe practice environment and sample data
Use one consistent dataset throughout the course.
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.
Use an isolated lab to make results repeatable, comparable and independent of production.
Do not run copied UPDATE or DDL examples in another database. Check DB_NAME() first.
One topic. Three levels of depth.
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.
Try it yourself first.
Check the lab tables and their row counts.
Show the solution and explanation
SELECT COUNT(*) AS OrderLineCount FROM lab.OrderItem;There should be 18 rows. Changing the fixture changes later expected results.