Relational model in Firebird with C#

Asked

Viewed 264 times

3

Developing a small C# project with Visual Studio, Firebird bank and ibexpert. With the tables WITHOUT RELATIONSHIP I can perform everything well. But I need to relate CLIENTE 1:N with BONUS And SAIDA. I am not able to develop the following reasoning:

I have a table called: CLIENTE with ID_CLIENTE (Primary key), ID_BONUS (FOREIGN KEY),ID_SAIDA (FOREIGN KEY), NOME and Data.

Table BONUS with ID_BONUS (Primary key), data , hour1, hora2, total. Table SAIDA with ID_SAIDA (Foreign key), data , hora1, hora2, total.

A Form1 to CLIENTE with DATAGRID and another Form2 for BONUS And SAIDA (2 DATAGRID).

I must put textbox for foreign keys on CLIENTE? And what can I call Form2, is by the primary key, from BONUS and SAIDA?

My No Relationship Code: 1 Search button on Form1 and a button that accesses Form2.

string mSQL = "Select * from CLIENTE Where ID_CLIENTE = " + id;
  • I think the tag [tag:model-relational] would fit better than [tag:].

1 answer

6

I believe you switched the balls, the foreign keys always stay on the side N.

Your tables would look something like this:


client table

  • id_client (primary key)
  • name
  • date

bonus table

  • id_bonus (foreign key, id_client reference)
  • date
  • hour1
  • hour2
  • total

table out

  • id_output (foreign key, id_client reference)
  • date
  • hour1
  • hour2
  • total

Depending on your business rule, you can even ask the user to place the foreign key, but this is not recommended as it opens many loopholes for failures. Ideally when you sign up a new bonus/output, make a select primary user key from the data you already have about it in the application.

Tip: Don’t concatenate a variable with a query, always use parameterized commands.

  • Hi Patrick.There is a lot not via Sql and this project asks. Thanks for the tip on foreign keys. It has given me a light.

  • @Cocoa, it is possible to use a FB resource to control id’s, it is called Sequence (which would be the same as mysql auto increment). A possible way to implement is at this link http://www.devmedia.com.br/auto-incremento-firebird/17924 Stay as a suggestion.

  • link specifically about sequences: http://www.firebirdsql.org/refdocs/langrefupd21-ddl-sequence.html

  • id_bonus and id_output should be local primary keys. Each of these tables should have an id_client that would be the foreign key referencing the client tabala id_client.

  • @Embarrassment, question of nomenclature, that’s just one example.

  • True. But it confuses who is starting or has no habit of working with it.

Show 1 more comment

Browser other questions tagged

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