简体   繁体   中英

How do I insert a record from one table into another table?

I was trying to set up a couple tables, and I noticed an error, so I created a blank database and tried to recreate the error.

The error reads "The columns in table "" do not match an existing primary key or UNIQUE constraint.

Now from what I've read from this site, it has to do with the primary key.

However what I want to do (my primary concern) is to have one table, have the roles, salaries and job description in one table, and in another table, have names, and roles. So for example, if there are two accountants in the 2nd table, I would like the 1 accountant entry in first table to apply twice to the second table. By doing this I have let's say 20 "roles" and 30 employees some with unique roles, some with the same roles.

How would I set it up so that the table would work this way?

PS:

I am using SQL Server Management Studio to create the database (which I am creating from scratch). How I created the problem, is I created a table and inserted two columns, column 1 is RolesID, and column two is Salary. In the second table is made up of two columns, Column 1 is Name, and column 2 is Position. I would like to add a 3rd column to Table 2, labelled Salary (or pay or something) in which if I had two of the same RoleID for two different Names, I would like the 3rd table to give the Salary. I haven't inserted any triggers yet.

For added Clarity: Is it possible, to simply have a table of all the possible roles + salaries, and ADD that to a different table automatically? If I put Name A, B, and C, and they have role A, A and B, I would like to have the salary automatically update for A, B and C accordingly, with only having to specify their role

I wasn't thinking clearly apparently.

The simple solution is to add Identifier Codes (IDs) for every table you want to represent.

For this, I had 1 table for Salary, and 1 table for roles and 1 table for contacts.

On a master table, you put a column for each of your IDs - contact ID, Salary ID, and Role ID. Fill in what those ID's are on the master table.

I simple put the ID numbers for each person on the table, and on my reporting software it placed the proper salaries and roles for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM