Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert multiple rows into composite primary key

Status
Not open for further replies.

jonmccon

Technical User
Joined
Aug 21, 2001
Messages
7
Location
US
I am trying to insert data from 2 tables (tblContacts and tblPermission)into another table (tblUserPermissions). The columns to which I need to insert the data in tblUserPermission (ContactID, and PermissionID) make up its primary key. Can anyone help me with this? Nothing I have tried has worked.
 
How do you join the contacts and permissions tables? JHall
 
You'll need to write a query similar to the following. I can't give you the full statement because the JOIN criteria for the two existing tables is needed.

Insert tblUserPermission
Select
tblContacts.ContactID,
tblPermission.PermissionID
From tblContacts
Inner Join tblPermission
On tblContacts.<ColName>=tblPermission.<ColName>

If there is no JOIN criteria, are you planning to add a row to the new table for every combination of rows from the two existing tables? If so you can use a Cross Join. However, I can't believe that you would want to give every user every permission. You must have some criteria for matching the two tables or selecting records.

Cross Join example:
Insert tblUserPermission
Select
tblContacts.ContactID,
tblPermission.PermissionID
From tblContacts
Cross Join tblPermission Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions in the SQL Server forum. Many of the ideas apply to all forums.
 
Thanks yet again, Terry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top