SQL Flow Field Guide

Change a temporary table

Create, alter, inspect, and remove a local lab table.

What you are trying to do

A learner needs to review a column and constraint change without touching a permanent object.

Work through it

  1. Check that the table name starts with the local temporary table marker.
  2. Trace the added CHECK constraint and test values.
  3. Confirm that the script removes its temporary table.

Check your work

The accepted lab values appear and the table is removed before the session continues.

Practice SQL

Open in SQL Flow
IF OBJECT_ID('tempdb..#LabStock') IS NOT NULL DROP TABLE #LabStock; CREATE TABLE #LabStock (ItemId int NOT NULL, Quantity int NOT NULL); ALTER TABLE #LabStock ADD CONSTRAINT CK_LabStock_Quantity CHECK (Quantity >= 0); CREATE INDEX IX_LabStock_Quantity ON #LabStock (Quantity); INSERT INTO #LabStock VALUES (1, 8), (2, 3); SELECT ItemId, Quantity FROM #LabStock ORDER BY ItemId; DROP TABLE #LabStock;

Commands in this lesson

Next lesson Roll back a lab change