You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, it is possible to insert an event two times in the database, causing waste of memory in the DB for having two events with the same values and making it impossible to get the event ID since it has two possible IDs for the given event values.
My suggestion is to only insert if there is no other event with the given values. We can do so by using a IF NOT EXISTS SQL statement:
IF NOT EXISTS(SELECT id FROM evento WHERE nome='event'AND data='01/01/2001')
BEGININSERT INTO evento (nome, data, img) VALUES ('event', '01/01/2001', 'img.png');
END
Also, it is possible to set the @evid variable otherwise with a ELSE, although it is unclear if that has some optimization improvement or not.
The text was updated successfully, but these errors were encountered:
To make this issue simpler the columns nome, data e img are now unique, in other words, you can not have two events with the same combination of those columns.
Currently, it is possible to insert an event two times in the database, causing waste of memory in the DB for having two events with the same values and making it impossible to get the event ID since it has two possible IDs for the given event values.
My suggestion is to only insert if there is no other event with the given values. We can do so by using a
IF NOT EXISTS
SQL statement:Also, it is possible to set the
@evid
variable otherwise with aELSE
, although it is unclear if that has some optimization improvement or not.The text was updated successfully, but these errors were encountered: