FEED TABLES (SQL SERVER )

Asked

Viewed 421 times

2

Opa Bom dia.

I have a sql database, in this database there is a table for People, it is a second table for registration of credentials, in a third table and made the association of the credential with the person, ie there is a table called CRED_PESSOAS, where through the person code is the credential number is made the credential association for person.

I have a client who asked to feed this credential information through scripts, already fed the two tables (PEOPLE AND CREDENTIALS) my doubt is how to create a condition, where I take for example the credential X for person Y, credential y for person x and so on.

Tabela que preciso Alimentar Tabela de Pessoas com o código que preciso para alimentar a tabela CRED_PESSOA

Thank you in advance. Gustavo Braga

  • Gustavo, welcome to stackoverflow in Portuguese, it would be nice to make a Tour, and edit your question with some information like; Which database? and which table structure?

  • OPA, Thanks for the tip I will pay more attention yes, but I do not know much of SQL is much less of this base just received this demand here in the office, commercial thing that sells what can not deliver kkk

  • Well, you’re entering this data, I believe you know which database this information is being stored in, and which table fields.

  • So I still don’t understand what you need to know exactly, the Database is SQL SERVER, the tables I’m feeding are the ones I mentioned, in the credential table I fed a column called CRED_NUMERO, as the credential number, In the Table PEOPLE I did in a type of Insert because people were already registered, from it I just need to take the PES_NUMERO to associate with the credential in the table CRED_PESSOAS

  • Ok, when a data is already inserted ( ... In the PEOPLE Table I did in a type of Insert because people were already registered, ...) what you do is an update to update the field, you need to take the PES_NUMERO, but how you will use this and what information you have to regasta this number?

  • I edited the post with two images, which should look better what I need.

  • Where is coming the data from a spreadsheet, database or application. Show how you did the other Insert and what you need to do, I still don’t know what you want.

Show 2 more comments

1 answer

1

You need a restrictive relationship between the tables, as an example below:

    SELECT pessoa.*, credencial.*
      FROM pessoa
INNER JOIN pessoa_credencial ON pessoa_credencial.id_pessoa = pessoa.id
INNER JOIN credencial ON credencial.id = pessoa_credencial.id_credencial

Remembering that the relationship in this way, if your database has more than one credential for the same person or more than one person for a credential) may return more than one line.

Obs.: The select I set is an example, not necessarily represents the structure of your tables, but indicates the correct way to make the relationship between the 3 tables you have.

Browser other questions tagged

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