Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (2.6k points)
recategorized by
Could someone tell me how can we insert multiple records using a stored procedure in MySQL?

1 Answer

0 votes
by (7.2k points)

 

CREATE PROCEDURE CompanyEmployee

  @EmployeeName NVARCHAR(50),

  @Students XML

AS

BEGIN

    DECLARE @StudenTable TABLE(Name NVARCHAR(50))

    DECLARE @EmployeeId INT

 

    INSERT INTO @StudenTable

    SELECT Tbl.Col.value('@Name', 'NVARCHAR(50)')

    FROM @Students.nodes('//Student') Tbl(Col)

 

    INSERT INTO CompanyEmployee VALUES(@EmployeeName)

    SET @EmployeeId = SCOPE_IDENTITY()

 

    INSERT INTO Student 

    SELECT @EmployeeId, Name FROM @StudenTable

END

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jun 26, 2020 in SQL by Sudhir_1997 (55.6k points)

Browse Categories

...