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
- Check that the table name starts with the local temporary table marker.
- Trace the added CHECK constraint and test values.
- 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 FlowIF 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