Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
296 B
1
Indexable
Never
DECLARE @new_book_id INT
SET @new_book_id = (SELECT COALESCE(MIN(book_id) + 1, 1) FROM books b1 WHERE NOT EXISTS(SELECT 1 FROM books b2 WHERE b2.book_id = b1.book_id + 1))

INSERT INTO books (book_id, title, author, status)
VALUES (@new_book_id, 'New Book Title', 'New Book Author', 'available')