Knowee
Questions
Features
Study Tools

Create a procedure named "insert_route"  which has key_id and route_name as the input parameter and status as output parameter. This procedure insert values into the table route. The values are passed as the input parameter to the procedure.Note:If the key_id value does not exists in the table, then set the status parameter as Inserted successfully.If the key_id value already exists in the table then you should handle the exception or warning by displaying the statusas Sorry

Question

Create a procedure named "insert_route"  which has key_id and route_name as the input parameter and status as output parameter. This procedure insert values into the table route. The values are passed as the input parameter to the procedure.Note:If the key_id value does not exists in the table, then set the status parameter as Inserted successfully.If the key_id value already exists in the table then you should handle the exception or warning by displaying the statusas Sorry

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a step-by-step guide to creating the procedure "insert_route" in SQL:

  1. First, you need to define the procedure. Use the CREATE PROCEDURE statement to do this. The syntax is as follows:
CREATE PROCEDURE insert_route
  1. Next, you need to specify the input parameters for the procedure. These are key_id and route_name. You also need to specify the output parameter, status. The syntax is as follows:
(
  IN key_id INT,
  IN route_name VARCHAR(255),
  OUT status VARCHAR(255)
)
  1. Now, you need to define the body of the procedure. This is where you specify what the procedure should do. In this case, you want to insert values into the route table. The syntax is as follows:
BEGIN
  DECLARE exist INT;
  SELECT COUNT(*) INTO exist FROM route WHERE id = key_id;
  IF exist = 0 THEN
    INSERT INTO route(id, name) VALUES(key_id, route_name);
    SET status = 'Inserted successfully';
  ELSE
    SET status = 'Sorry';
  END IF;
END;
  1. Finally, you need to end the procedure definition with a semicolon. The complete procedure definition is as follows:
CREATE PROCEDURE insert_route
(
  IN key_id INT,
  IN route_name VARCHAR(255),
  OUT status VARCHAR(255)
)
BEGIN
  DECLARE exist INT;
  SELECT COUNT(*) INTO exist FROM route WHERE id = key_id;
  IF exist = 0 THEN
    INSERT INTO route(id, name) VALUES(key_id, route_name);
    SET status = 'Inserted successfully';
  ELSE
    SET status = 'Sorry';
  END IF;
END;

This procedure first checks if the key_id exists in the route table. If it does not exist, it inserts the key_id and route_name into the table and sets the status to 'Inserted successfully'. If the key_id does exist, it sets the status to 'Sorry'.

This problem has been solved

Similar Questions

Create a procedure named 'insertRoute' which has route_name as an input parameter with varchar as its datatype. This procedure should take the count of the existing table records(route table) and add 1 with that to generate the new route id.The newly generated id along with the route_name should be inserted into the route table.Hints:Procedure name : insertRouteParameters : route_name is type of varchar

Write a query to insert any 4 records into the 'route' tabl

Write a query to insert any 4 records into the 'route' table.Note:1. You can provide any values to the columns of route table. Ensure the values matches with the data type of those columns.2. Insert only 4 records into the table. SubmitSaveExecutePrevious Submission

Write a query to insert any 4 records into the 'route' table.

rite a query to insert any 4 records into the 'route' table.Note:1. You can provide any values to the columns of route table. Ensure the values matches with the data type of those columns.2. Insert only 4 records into the table.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.