我想讓我的一個表中的字段/變量傳輸到另一個表。變量是當前用戶的用戶標識。這兩張桌子之間有關係。當用戶註冊一個賬戶時,就爲他們創建了一個UserId。然後我希望用戶能夠存儲關於他們自己的其他細節(存儲在不同的表中)。這些項目應該鏈接到用戶。我如何讓當前用戶的UserId附加到他們提交給其他表的細節上?這是自生成的SQL命令爲我做的Visual Studio:Microsoft SQL確保用戶標識在兩個表中相同
SelectCommand="SELECT [Bhousenum], [Bstreetname], [Bcity], [Bcounty], [Bcountry], [Dhousenum], [Dstreetname], [Dcity], [Dcounty], [Dcountry], [Dpostcode], [Bpostcode], [mobilenum], [credittype], [creditname], [creditnum], [securitycode], [creditexpiry], [dob], [UserId] FROM [Customers] WHERE ([UserId] = @UserId)"
DeleteCommand="DELETE FROM [Customers] WHERE [UserId] = @UserId"
InsertCommand="INSERT INTO [Customers] ([Bhousenum], [Bstreetname], [Bcity], [Bcounty], [Bcountry], [Dhousenum], [Dstreetname], [Dcity], [Dcounty], [Dcountry], [Dpostcode], [Bpostcode], [mobilenum], [credittype], [creditname], [creditnum], [securitycode], [creditexpiry], [dob], [UserId]) VALUES (@Bhousenum, @Bstreetname, @Bcity, @Bcounty, @Bcountry, @Dhousenum, @Dstreetname, @Dcity, @Dcounty, @Dcountry, @Dpostcode, @Bpostcode, @mobilenum, @credittype, @creditname, @creditnum, @securitycode, @creditexpiry, @dob, @UserId) WHERE [UserId] = @UserId"
UpdateCommand="UPDATE [Customers] SET [Bhousenum] = @Bhousenum, [Bstreetname] = @Bstreetname, [Bcity] = @Bcity, [Bcounty] = @Bcounty, [Bcountry] = @Bcountry, [Dhousenum] = @Dhousenum, [Dstreetname] = @Dstreetname, [Dcity] = @Dcity, [Dcounty] = @Dcounty, [Dcountry] = @Dcountry, [Dpostcode] = @Dpostcode, [Bpostcode] = @Bpostcode, [mobilenum] = @mobilenum, [credittype] = @credittype, [creditname] = @creditname, [creditnum] = @creditnum, [securitycode] = @securitycode, [creditexpiry] = @creditexpiry, [dob] = @dob WHERE [UserId] = @UserId">
http://en.wikipedia.org/wiki/Foreign_key - 請閱讀此處,它應該開始落實到位:) – Dave 2013-05-01 10:35:50