5 Replies - 609 Views - Last Post: 17 March 2018 - 11:53 AM Rate Topic: -----

#1 Foobarer   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 269
  • Joined: 28-March 17

Do I have to use constraints for simple database?

Posted 16 March 2018 - 01:59 PM

I've just came across "constraints" and until now I haven't used them. (I'm a beginner)
I have 3 tables currently: One for the 'registered users', second for 'surveys by user' and third is 'available locations' (countries, cities)

And for example in surveys by user, I have a column called user_id, which is the same user_id from 'registered users' table - so I can find them using queries.
I saw that whenever you have such connection of tables (when column is referring to or is referred by another table) then you should have 'constraint' - in this case the user_id.

but I haven't encountered any problems yet. What would be my use for it? Any examples? or explanations?

Thanks!

This post has been edited by Foobarer: 16 March 2018 - 02:00 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Do I have to use constraints for simple database?

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2791
  • View blog
  • Posts: 11,001
  • Joined: 03-December 12

Re: Do I have to use constraints for simple database?

Posted 16 March 2018 - 02:02 PM

An example would be, you delete a user. You are left with orphan records that donít belong to a user
Was This Post Helpful? 1
  • +
  • -

#3 Foobarer   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 269
  • Joined: 28-March 17

Re: Do I have to use constraints for simple database?

Posted 16 March 2018 - 02:19 PM

thank you!
OK I got the benefit of that!

You're right, I haven't included an option to delete a user yet, but I should do that.
If I will constraints correctly, and I will give a user an option to delete itself, then it will automatically delete the rows, that's great
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2791
  • View blog
  • Posts: 11,001
  • Joined: 03-December 12

Re: Do I have to use constraints for simple database?

Posted 16 March 2018 - 02:35 PM

Soft deletes are better. You set a column flag saying it has been removed and when you do a query, you filter on that flag.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6775
  • View blog
  • Posts: 27,938
  • Joined: 12-December 12

Re: Do I have to use constraints for simple database?

Posted 16 March 2018 - 02:40 PM

Deleting records should be rare and controlled.

It is preferable to include a column such as "Inactive" and to, at some future, regular, point, archive these records. That is, delete them, but copy them first to an historic table and/or database.
Was This Post Helpful? 2
  • +
  • -

#6 Foobarer   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 269
  • Joined: 28-March 17

Re: Do I have to use constraints for simple database?

Posted 17 March 2018 - 11:53 AM

I will do that instead of deleting, thanks! (just added an "inactive" column, need to figure out how to change everything to work with inactive instead of deleted :baaa: )
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1