Can I have a settings table without primary key?

0

In database, this table will be for information storage and will only have one row, which may be updates and initialize null and over the course of the program will be added. Is it possible to have a table without primary key for this function? And how to perform select? SELECT dado1, dado2, dado3 FROM table ? Thank you in advance.

    
asked by anonymous 12.06.2017 / 18:21

2 answers

1

It's quite complicated to respond without knowing the context you're working on. We usually create a configuration file (.ini, .properties or .conf) and burn to disk for local programs. In the WEB we created some session variable. If you really want to write to database, my suggestion is to create a table with 3 fields (ID, Key, Value). So you can store as much information as you need. ID = primary key of the table; Key = indicates the meaning of the value field; Value = the information you want to save.

    
12.06.2017 / 18:45
0

Yes, you can have this table of settings without a primary key. When fetching, you will add a LIMIT 1 to bring only one line in the result.

Although I believe that including the primary key is more appropriate, it will bring more benefits than problems. If at some point you need to have more than one configuration line, you can use the ID to do UPDATE or DELETE. So I suggest adding the primary key column.

    
12.06.2017 / 18:37