Write a stored procedure that prints the numbers from 1 to 10.
1
Times asked
Aug 2026
Last seen
Aug 2026
First seen
💡 Model Answer
In SQL Server you can create a simple stored procedure that uses a WHILE loop to print numbers 1 through 10:
sql
CREATE PROCEDURE PrintOneToTen
AS
BEGIN
DECLARE @i INT = 1;
WHILE @i <= 10
BEGIN
PRINT @i;
SET @i = @i + 1;
END
END;
GO
Calling EXEC PrintOneToTen; will output the numbers 1 to 10 in the Messages tab. The procedure declares a counter, loops until it reaches 10, prints the current value, and increments the counter. The logic is straightforward and demonstrates basic procedural control flow in T‑SQL.
Sign in to unlock the rest of this answer
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500