Picture 7.1
Question 8:
Create a stored procedure named insertAuthor with @authorID int, @author Name nvarchar(100), @country nvarchar(100), @sex nvarchar(10), @yearOfBirth int as input parameters of the procedure. The stored procedure attempts to insert a new author into the table Authors, but only if an author with the same AuthorID does not already exists:
- if an author with AuthorID = @authorID already exists, the procedure does nothing.
if there is no author with AuthorID = @authorID, the procedure will insert into the table Authors a new row with @authorID, @authorName, @country, @sex, @yearOfBirth as values for its attributes.
For example, when we execute the insertAuthor procedure with input values as in the following statement, a new author with the corresponding values will be inserted into the table Authors:
exec insertAuthor
@authorID = 100,
@authorName = 'Guillaum Musso',
@country = 'France',
@sex = 'Male',
@yearOfBirth = 1975;
But when we run the following statement to execute the insertAuthor procedure, the command completed successfully but no row will be inserted into the table Authors because an author with AuthorID = 1 already exists in the table.
Close
+ 100%
Zoom