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 4562740
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:15:32+00:00 2026-05-21T18:15:32+00:00

How could I want to add a column if not exist. I tried this

  • 0

How could I want to add a column if not exist.
I tried this code:

IF EXISTS( SELECT NULL
            FROM INFORMATION_SCHEMA.COLUMNS
           WHERE table_name = 'forwind.measuringdata_fino_10_00000000'
             AND table_schema = 'forwind'
             AND column_name != 'F1_USA(40)_u')  THEN

  ALTER TABLE `forwind.measuringdata_fino_10_00000000` ADD `F1_USA(40)_u` FLOAT NOT NULL default '0';

END IF; 

but I get the following error:

Error Code: 1064 You have an error in
your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near ‘IF EXISTS( SELECT NULL
FROM INFORMATION_SCHEMA.COLUMNS

Good for me if somebody know an other solution!

  • 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-05-21T18:15:33+00:00Added an answer on May 21, 2026 at 6:15 pm

    MySQL does not support anonymous IF statements like that.

    You have at least 3 options to address this:

    1) Just run the ALTER TABLE statement and ignore the Duplicate column name error if the column already exists. If you’re executing a bunch of DDL in a script you can use mysql -f to ignore the errors and keep going.
    2) Use a scripting language such as bash, python, perl etc to check for the existence of the column and then add it if it does not already exist.
    3) Create a stored procedure in MySQL to check for the existence of the column and then add it if it does not already exist.

    P.S. As an aside, I recommend against putting parentheses in column names, because that forces you to quote the column name every time you reference it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add 1 year to a datetime-type column in every single row
Given this: create table Location( LocationId int identity(1,1) not null primary key, Address nvarchar(max)
I want to add style in ASP.NET textbox control. I couldn't find textbox element
Could someone please explain when would I want to use delegation instead of inheritance?
I want to build an application using Quicktime ActiveX interop that could run on
I want to create a high performance server in C# which could take about
I want the value of JavaScript variable which i could access using PHP. I
I want to implement a method in java that could be used to categorize
I want to know that how the details of the viewers could be traced
I want to parse XML in bash and xpath could do it. (To get

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.