Can I have a settings table without Primary key?

Asked

Viewed 2,012 times

0

In a database, this table will be for storing information and will have only one line, and there may be updates and will initialize null and during 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.

  • The problem isn’t even how to do the select and yes how to do the update. Although, for all intents and purposes, a Where-free update would do.

  • Yes, then I wouldn’t use Where. I’ll go by id that bother me less hehe, hugs and thanks.

2 answers

1


It’s quite complicated to answer without knowing the context you’re working on. We usually create a settings file (.ini, .properties or .conf) and save to disk for local programs. On the WEB we create some session variable. If you really want to write to a database, my suggestion is to create a table with 3 fields (ID, Key, Value). So you can store as much different 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.

  • Yes, actually in some parts I use . properties in others one . txt normal, but it is necessary to implement with DAO, this data will be displayed in software fields allowing only the first insertion and as many editions as the user wants. This software is an evaluation tool in a CDC chair. Thanks.

0

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

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

  • 1

    In addition I would make a Rigger of before Insert and delete in this table , if it is triggered would generate an error to prevent the operation, this would guarantee a single record in the table. Any operation allowed would be UPDATE and with only one record would not need a primary key.

  • @Motta the bank I use is kind of shitty, let’s say, has no support for anything, and the syntax is different from the db I worked/have knowledge of. And besides there is no tool case for it, I am obliged to do everything in hand, this.

  • @Diego Keller I will need only one line anyway, it is to store the information of the "company", thanks for the tip, I think I will use even an id, I only came up with this doubt while modeling.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.