I want to assign the total number of rows to a variable named "@row_count".
DECLARE @row_count int
SET @row_count = SELECT COUNT(*) FROM information
I know. I'm doing wrong. But I haven't found anything on how to do it.
I want to do something like that:
CREATE PROC add_person
(
@id tinyint,
@name nvarchar(max),
@surname nvarchar(max),
@salary int,
@job nvarchar(max)
)
AS
BEGIN
INSERT INTO information
VALUES(@id,@name,@surname,@salary,@job)
END
DECLARE @row_count nvarchar(max)
SET @row_count = SELECT COUNT(*) FROM information
BEGIN TRAN
add_person 34,'asdf','asdf',3000,'asdf'
IF @row_count > 33
ROLLBACK TRAN
ELSE
COMMIT TRAN
GO;
My goal: to prevent the addition of new people if the number of people exceeds thirty-four.