How do i copy / insert a Primary Key value of one table into another table?

 

Hi

i have set up  two very simple tables, I want a user to be able to create a basic account ( data stored in User_Profile  table with Id set as the Primery Key as Identity) I want the user to be able to be able to return to their account at a later date and then post multiple reviews of different bands they have seen at a later date. I kept the tables in my example very simple so I could get my head around the concept, but generally, I want to connect the Id (PK) value in User_Profile table to the User_Id filed in the User_Review table, so every review that user writes, will be connected directly to their Id.

 
 

Any help you could give would be fantastic a i have no idea where to start!!!

 

 

User_Profile

Id   int,  ( as primary Identity Key)

Name

City

Country

 

I have a second table called User Reviews

 User_Revews

Revew_Id   int ,  ( as primary Identity Key)

User_Id  int, ( I want this to contain the Id value in the User profile Table)

Review_Details

 

 

Thanks

 

Odxsigma

0
odxsigma
12/10/2007 7:44:03 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

3 Replies
970 Views

Similar Articles

[PageSpeed] 30

 

set up a foreign key constraint on the UserId in the user review table...and pass it the userid of the user that is doing the update....

A) set up FK on that field

b) pass the user id of the membership stuff. -> here is how with a new user

Dim userGuid As Guid = CType(newUser.ProviderUserKey, Guid)

c) insert that guid in the field....if it does not match you will get an error since it is a FK

 

cheers


Joël Hébert [MVP ASP.NET]

Opulent ASP Development Inc.
www.opulentasp.com
Ottawa,Canada

Click "Mark as Answer" on the posts that helped you to help future readers to get the solutions
0
Joël
12/10/2007 9:48:01 PM

 u make the User_id as foreign key for this ,the base table will be user profile.Here the concept is the id values of the user profile will be included in user reviews in the column User_id i means when u  r going to add the entries into user_reviews u have to pass the id value(s).

Thank u

Baba

Please remember to click "Mark as Answer" on this post if it helped you. 

 


Thank u

Baba

Please remember to click "Mark as Answer" on this post if it helped you.
0
srijaya_ramaraju
12/11/2007 6:04:48 AM

 Refer http://forums.asp.net/t/1175542.aspx for help on setting relations between tables using primary key and foreign key.

Your table design looks fair enough.  After setting the relationship, whenever you try to insert a record in the user_review table, you must have a valid user_id ( and id which is there in the user_profile table) to insert with.

Hope this will help.


Thanks,
Dhimant Trivedi
"When the going gets tough, tough gets going."

"Mark as Answer" the post(s) which helped you solve the problem
0
dhimant
12/11/2007 7:00:40 AM
Reply:

Similar Artilces:

How do obtain Primary Key value from one table aid insert it into another table?
Hi  I have one table called User profile and another table called User Reviews, basically I want to write a query or stored procedure( I don’t know what is best) so that when a registered writes a review, their Id in the User_Profile table is inserted into the User_Review Table in the User_Id field. This is to allow a single user to create multiple reviews.  Can anyone help me with how the code / SLQ query should look to achieve this?  User_Profile Id   int,  ( as primary Identity Key) Name City Country  I have a second table called User Rev...

Copy values from one table to another table using LINQ to SQL?
Hello,I have two database tables that have different names but identical structure (columns).What is the easiest way to copy the values from one table to the other table using LINQ to SQL? Thanks,-- shawn shawn Hi, As far as I research, we could use "foreach"  to insert the data from one table to another table. The code is shown below.         //there exist two table list and listSecond        DataClassesDataContext dataClass = new DataClassesDataContext(); //create the instance of the DataCon...

insert multiple values from one table into one column from another table?
Hi, I'm attempting to create an insert statement that gets the values from multiple columns and insert them into one column from another table, is there a simple solution to do this?Here is something similar to what i'm wanting done, just it's not the correct way to do it, i want value1, value2 and value3 from one table to be combined and put into the value1 column of another table, what am i doing wrong? INSERT INTO tablename2 (value1 + value2 + value3)SELECT value1FROM tablename1 thanks in advance! INSERT INTO tablename2 (SELECT val1 + val2 + val3 FROM tabl...

How to insert a table into another table and avoid primary key duplication ?
I have a table that I need to add every month to my master table, sometimes I get some rows in the monthly table that already are in the master, so, when I do: "insert into smi select * from smi_temp" I get a message saying that there was a primary key violation and no row is inserted. Is there a way to continue inserting the correct data ? Thank you for your help. >I have a table that I need to add every month to my master table, sometimes >I get some rows in the monthly table that already are in the master, so, >when I do: >"insert into smi sele...

is there an sql statement to insert data to one table and getting the data from another table
Ok I have a table that have general categories with just name and CatNo. Now what I want to know is when I create a client to move all the data in general categories to another table called categories that have the clientid to associate it with the client. I would appreciate for any help what is your question here??Shravan Addaypally MCP...

copy data from one table to another with addition insert value
Hi,  I was wondering if you can help. In my vb.net form I am running a query to insert data from one database table to another.  However what I need to do is to be able is to add the id of a record I have just created to this insert into sql command. I have managed to use @@ identity to get the id of my first sql insert statement but I am wondering how I can use it in the second insert into and select statement. At the moment my sql statement just copies exactly what is in the select statement. I can't figure out how to add the @@identity value to my second sql statement...

Inserted records missing in sql table yet tables' primary key field has been incremented.
I have a sql sever 2005 express table with an automatically incremented primary key field. I use a Detailsview to insert new records and on the Detailsview itemInserted event, i send out automated notification emails. I then received two automated emails(indicating two records have been inserted) but looking at the database, the records are not there. Whats confusing me is that even the tables primary key field had been incremented by two, an indication that indeed the two records should actually be in table.  Recovering these records is not abig deal because i can re-enter them but ia...

How to copy table and all it's primary and foreign key relationships from one db to another?
I'm ready to deploy my first .net application from my test server to my production server, but don't know how to copy the database and it's tables, permissions, primary keys, foreign keys, etc.   How do I do this?  Never make important decisions on a Monday! Right click on the database, go to Tasks, then Copy Database and follow the wizard....

copy column from one table to another table
Hi, I have 2 tables. Table1 has column1 and column2. I wish to copy column1 into Table2 by using sql statement. How do i do that? Thank you. In general you'd do it like this: Insert statement: INSERT INTO Table2 ( Column1 ) SELECT Column1 FROM Table1 Update statement: UPDATE Table2 SET Column1 = T1.Column1 FROM Table2 T2 INNER JOIN Table1 T1 ON T2.someID = T1.someID TerriTerri MortonEngagement Manager, NeudesicHow to ask a question...

inserting data from one table to another table..
Hi Guys!  I am stuck on inserting data. Hope you will help me. I have two tables name Customer and Address; Customer(cust_id,name,add_fk);    fk=foreign key,  cust_id and add_id are primary key Address(add_id,street,city,zip); Now, how can I retrieve add_id from Address table and insert into Customer table ( in the add_fk field) using stored procedure with parameters? I am using Oracle 9i.  I would appreciate your help. Thanks! Are you using any of this data in between these actions? (eg: Are they going to reside in your page in a grid, or formview?) ...

SQL
I am getting info from one table, CalibrationReview, that is not inanother table, tblEquipments. SELECT EquipmentNumber, Model, SerialNumber, Make, CalLabName, CalDateFROM CalibrationReviewWHERE NOT EXISTS (SELECT AssignedID FROM tblEquipments WHERE AssignedID = CalibrationReview.EquipmentNumber) Now, I need to take these rows and INSERT them into tblEquipments,but with some conditions. tblEquipments has some contraints, so, the following needs to be done: Using dbo.CalibrationReview.EquipmentNumber, get CalibrationMaster.TestTechnology where dbo.CalibrationReview.EquipmentNumber = dbo.C...

Passing value from one control to another and inserting that value in a table
Hey all, sorry if the subject is confusing or has already been covered, but I have (obviously) a problem (at least one).This is using:Visual Studio 2005ASP.NET 2.0SQL Server 2005 ExpressVisual Basic I'm building a CRM system for my company and have run into a snag when attempting to add new customer records for a given client. The first thing that any CSR (or admin) must do upon accessing the CRM system is choose which client's customers they are actually working with (we have multiple clients and are ultimately responsible for providing customer service to the clients' end ...

SQL statement failed, no primary key value for foreign key ... in table ...
Problem: SQL statement failed, no primary key value for foreign key ... in table ... After deleting or changing primary key values in either consolidated or remote database. Question: Are there any triggers that can resolve inserting a record that has a foreign key value with no existing primary key value in primary table? Description: We have a serious problem with the dbremote program. I think it's a general problem that could appear in every database with related tables. Everytime the problem turns up we must create new remote databases from the consolidated datab...

Insert multiple records from one table to another table
Hello. Got a quick problem. I need to post shopping cart items from a temperary table "ShopCart" to a permanent table "tbl_orders". Problem is, I cannot figure out how to iterate through the recordset to post the unique products from "ShopCart" to "tbl_orders". The code below inserts the first product-- but that's it. If there are 6 different products, it will insert the first product 6 times. Public Sub GetShopCart() Dim ordernumber = session("ordernumber") Dim objConn as new SqlConnection(strConn) Dim strSQL as Str...

Web resources about - How do i copy / insert a Primary Key value of one table into another table? - asp.net.sql-datasource

Primary market - Wikipedia, the free encyclopedia
of securities dealers. The process of selling new issues to investors is called underwriting . In the case of a new stock issue , this sale is ...


Report: Samsung to be Apple’s primary OLED display supplier as it invests up to $7.5B in readiness
Korea’s ET News claims that Samsung will become Apple’s primary supplier of OLED display panels, stating that an agreement has “practically been ...


Darby helped secondary become a primary asset
This is the eighth of a nine-part positional review of the Buffalo Bills’ 2015 season. Today’s installment looks at the defensive backs. By Vic ...

Cruz and Trump clash in 6th Republican primary debate - Videos - CBS News
Less than three weeks before the first primary votes are cast, GOP rivals Donald Trump and Ted Cruz are fighting for the lead in Iowa. “Face ...

SNL's Hilarious Satire Of Fox Business GOP Presidential Primary Debate
NBC's Saturday Night Live did a tremendous job of spoofing the latest Republican presidential primary debate that appeared on the Fox Business ...

Open thread for night owls: Virginia officials worry of Trump voter 'mayhem' on primary day
... primaries, saying they fear that supporters of Republican front-runner Donald Trump could cause mayhem at the polls. At issue is a primary ...

Primary Stupid
What drives me nuts about primary season is that I see too many people who I normally think are quite smart making transparently stupid arguments ...

The GOP Primary, In One Debate
If you’d spent the past eight months hiking the Appalachian Trail, and Thursday night’s GOP presidential debate was the first whiff you’d gotten ...

Resources last updated: 1/20/2016 12:14:41 PM