MySQL table creation

Discussion in 'Spigot Plugin Development' started by Justin393, Dec 10, 2015.

  1. Right now I'm trying to create a MySQL table to store player information, such as UUID, level, etc.

    I'm just not entirely sure how to setup the table properly and feel like I'm doing it wrong. Any suggestions/criticism would be great.
    • Agree Agree x 1
  2. If you're using Java 7+, I recommend using try-with-resource statements.
    On the note of the MySQL query, here's a great resource on creating tables:

    I also recommend looking into foreign keys and constraints ( so you can reduce error-prone queries and ensure relational tables are updated properly.

    - MySQL engines
    - MySQL charset

    Great answer on when to use backticks, single quotes, double quotes and why.

    If I had more time to post an example and explain it I would. If you don't get an answer for a while please ping me @Wingz and I'll make some examples.
    #2 Wingz, Dec 10, 2015
    Last edited: Dec 10, 2015
    • Useful Useful x 1
  3. Thanks for the useful posts! I think I understand it now, I'll try it tomorrow and see how it goes. One thing that I want to know first though. Is it possible to add more columns later on? I don't want to add say 6 columns only to end up needing 8 layer on or something.
  4. Definitely. You can create an empty skeleton table with 1 column and manipulate it as you go. That's part of altering a table. You can drop a column, add a column, etc.

    There are points in which you want to start tracking new data for say a player, it's easy to just:
    ALTER TABLE `tbl_name` ADD COLUMN `col_name` column_definition
    • Creative Creative x 1