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

  • Home
  • SEARCH
  • 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 6830695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:38:56+00:00 2026-05-26T22:38:56+00:00

I want to create an enum within an enum for sql query in java.

  • 0

I want to create an enum within an enum for sql query in java. For example I want to say table.create and it would return CREATE TABLE or database.create and it would return CREATE DATABASE. How can I do this?

enum SQL {
    table("ALTER,CREATE"),
    database("CREATE");
}
  • 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-26T22:38:57+00:00Added an answer on May 26, 2026 at 10:38 pm

    Why make it an enum within an enum?

    Table.java

    public enum Table {
        CREATE("CREATE TABLE"),
        ALTER("ALTER TABLE");
    
        private String cmd;
    
        Table(String cmd) {
           this.cmd = cmd;
        }
    
        @Override
        public String toString() {
            return cmd;
        }
    }
    

    Database.java

    public enum Database {
        CREATE("CREATE DATABASE");
    
        private String cmd;
    
        Database(String cmd) {
           this.cmd = cmd;
        }
    
        @Override
        public String toString() {
            return cmd;
        }
    }
    

    With this example, System.out.println(Table.CREATE); prints CREATE TABLE.

    This will also aid in readabilty becuase you can produce code like:

    String query = Table.CREATE + "(Column1 " + DbType.INTEGER + " " + Column.UNIQUE + " " + Column.PRIMARY_KEY + ")";
    

    Which would be a bit easier to read and understand, IMO.

    EDIT

    To attempt to get close to what you’re after you could do something like:

    public enum SQL {
        TABLE("TABLE", SQL.CREATE_FLAG | SQL.ALTER_FLAG),
        DATABASE("DATABASE", SQL.CREATE_FLAG);
    
        public static final int CREATE_FLAG = 1;
        public static final int ALTER_FLAG = 2;
    
        public static final String CREATE_STRING = "CREATE";
        public static final String ALTER_STRING = "ALTER";
    
        public static final String INVALID = "INVALID";
    
        private String name;
        private boolean create;
        private boolean alter;
    
        SQL(String name, int flags) {
            create = (flags & CREATE_FLAG) != 0;
            alter = (flags & ALTER_FLAG) != 0;
    
            this.name = name;
        }
    
        public String create() {
            if (create)
                return CREATE_STRING + " " + name;
            else
                return INVALID;
        }
    
        public String alter() {
            if (alter)
                return ALTER_STRING + " " + name;
            else
                return INVALID;
        }
    }
    

    Where you can call:

    System.out.println(SQL.TABLE.create());    // CREATE TABLE
    System.out.println(SQL.TABLE.alter());     // ALTER TABLE
    System.out.println(SQL.DATABASE.alter());  // INVALID
    System.out.println(SQL.DATABASE.create()); // CREATE DATABASE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can create an empty Java enum type, but when i want to add
I want to create a class with a nested enum. public class Foo {
I just want to understand why I cannot create a protected enum on C#?
I want create a excel with Apache POI in java and I must insert
I want to create 5 variables of type array all at once. Is this
I want to create string ENUM in c#. Basically i wan't to set form
I want to limit the datatype value that can be stored within a field
Can I create an enum (constants to use in a switch statement) from two
I want to create an enum-like set of strings in a way that will
I have a table which maps String->Integer. Rather than create an enum statically, I

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.