Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Write a script that attempts to insert a new category named “Guitars” into th

ID: 3740924 • Letter: 3

Question

3. Write a script that attempts to insert a new category named “Guitars” into the Categories table. If the insert is successful, the script should display this message: SUCCESS: Record was inserted. SQL, Murach

If the update is unsuccessful, the script should display a message something like this: FAILURE: Record was not inserted. Error 2627: Violation of UNIQUE KEY constraint 'UQ__Categori__8517B2E0A87CE853'. Cannot insert duplicate key in object 'dbo.Categories'. The duplicate key value is (Guitars)

Explanation / Answer

USE MyGuitarShop;
BEGIN TRY
INSERT INTO Categories(CategoryName)
VALUES('Guitars')
PRINT 'SUCCESS: Record was inserted'
END TRY
BEGIN CATCH
PRINT'FAILURE: Record was not inserted.';
PRINT 'ERROR'+CONVERT(varchar,ERROR_NUMBER(),1)+': '+ERROR_MESSAGE()
END

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote