Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8167901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:20:58+00:00 2026-06-06T20:20:58+00:00

I am creating a SQL script file in MySQL. The script simply creates a

  • 0

I am creating a SQL script file in MySQL. The script simply creates a table and some stored procedures. I have two questions.

  1. I need to check if table exists, skip the create table statement.
    But if procedure exists, drop it and then create a new one. Here is
    the code I am trying –

    CREATE TABLE IF NOT EXISTS Student (   
        Id INT PRIMARY KEY,   Name
        VARCHAR(100) NOT NULL 
    );
    
    DROP PROCEDURE IF EXISTS usp_StudentInsert;
    
    DELIMITER $$
    CREATE PROCEDURE usp_StudentInsert(
        id INT, 
        name VARCHAR(100)) 
    BEGIN    
        INSERT INTO Student(Id, Name) VALUES(id, name); 
    END$$
    
    DROP PROCEDURE IF EXISTS usp_StudentRetrieve;
    
    DELIMITER $$ 
    CREATE PROCEDURE usp_StudentRetrieve(studentId INT)
    BEGIN
        SELECT * FROM Student WHERE Id = studentId;
    END$$
    

    There is an error “SQL Syntax Error near DROP PROCEDURE IF EXISTS
    usp_StudentRetrieve”;

  2. What is best way to execute script file using PHP code?

Thank you in advanced.

Ritesh

PS – I am using MySQL Workbench V5.2 with MySQL 5.1, if it helps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:21:00+00:00Added an answer on June 6, 2026 at 8:21 pm

    I added a space after delimiter and it works for me:

    from delimiter$$ to delimiter $$

    mysql> CREATE PROCEDURE usp_StudentInsert(id INT,name VARCHAR(100)) 
        -> BEGIN
        ->  INSERT INTO Student(Id, Name) VALUES(id, name); 
        -> END
        -> $$
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> delimiter ;
    mysql> drop procedure usp_studentinsert;
    Query OK, 0 rows affected (0.00 sec)
    

    EDIT:

    mysql> DROP PROCEDURE IF EXISTS usp_StudentInsert;
    Query OK, 0 rows affected (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an SQL file, placing this file into a zip file with some
I've written a big sql script that creates a CSV file. I want to
Have a Sql Script file name spCreation.sql with the following contents. CREATE PROCEDURE dbo.usp_select_customers
We have an SQL script in a .sql file. It has a couple of
I'm creating a sql based procedure which can Accept a table load the values
I'm working on creating a SQL query that will pull records from a table
I have a LinqToEntities query that double produces a subquery when creating the SQL.
I have a problem creating the following SQL Statement using LINQ & C# select
I would appreciate some help on creating the proper SQL to retrieve only one
I have a rails project where I need to add some default values to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.