Table UserId row population
-
Hi there, I am fairly new to programming SP, I am trying to create a relationship between to tables in my database. The tables are aspnet_Membership and aspnet_Genealogy, I have setup a relation with the two tables using a PK in the table aspnet_Membership and a FK in the table aspnet_Genealogy as can be seen in the code below:
CREATE TABLE [dbo].[aspnet_Genealogy] (
[GenealogyId] INT IDENTITY (1, 1) NOT NULL,
[UserId] UNIQUEIDENTIFIER NULL,
[FamilyName] CHAR (200) NOT NULL,
[FirstName] CHAR (200) NULL,
[MiddleName1] CHAR (200) NULL,
[MiddleName2] CHAR (200) NULL,
[MiddleName3] CHAR (200) NULL,
[Gender] CHAR (10) NULL,
[DOB] VARCHAR (20) NOT NULL,
[COB] CHAR (200) NULL,
[SOB] CHAR (200) NULL,
[COOB] CHAR (200) NULL,
[Newsletter] CHAR (10) NULL,
[DateTimeGenealogy] DATETIME NOT NULL,
PRIMARY KEY CLUSTERED ([GenealogyId] ASC),
CONSTRAINT [FK_aspnet_Genealogy_aspnet_Membership] FOREIGN KEY ([UserId]) REFERENCES [dbo].[aspnet_Membership] ([UserId])
);and
CREATE TABLE [dbo].[aspnet_Membership] (
[ApplicationId] UNIQUEIDENTIFIER NOT NULL,
[UserId] UNIQUEIDENTIFIER NOT NULL,
[Password] NVARCHAR (128) NOT NULL,
[PasswordFormat] INT DEFAULT ((0)) NOT NULL,
[PasswordSalt] NVARCHAR (128) NOT NULL,
[MobilePIN] NVARCHAR (16) NULL,
[Email] NVARCHAR (256) NULL,
[LoweredEmail] NVARCHAR (256) NULL,
[PasswordQuestion] NVARCHAR (256) NULL,
[PasswordAnswer] NVARCHAR (128) NULL,
[IsApproved] BIT NOT NULL,
[IsLockedOut] BIT NOT NULL,
[CreateDate] DATETIME NOT NULL,
[LastLoginDate] DATETIME NOT NULL,
[LastPasswordChangedDate] DATETIME NOT NULL,
[LastLockoutDate] DATETIME NOT NULL,
[FailedPasswordAttemptCount] -
Hi there, I am fairly new to programming SP, I am trying to create a relationship between to tables in my database. The tables are aspnet_Membership and aspnet_Genealogy, I have setup a relation with the two tables using a PK in the table aspnet_Membership and a FK in the table aspnet_Genealogy as can be seen in the code below:
CREATE TABLE [dbo].[aspnet_Genealogy] (
[GenealogyId] INT IDENTITY (1, 1) NOT NULL,
[UserId] UNIQUEIDENTIFIER NULL,
[FamilyName] CHAR (200) NOT NULL,
[FirstName] CHAR (200) NULL,
[MiddleName1] CHAR (200) NULL,
[MiddleName2] CHAR (200) NULL,
[MiddleName3] CHAR (200) NULL,
[Gender] CHAR (10) NULL,
[DOB] VARCHAR (20) NOT NULL,
[COB] CHAR (200) NULL,
[SOB] CHAR (200) NULL,
[COOB] CHAR (200) NULL,
[Newsletter] CHAR (10) NULL,
[DateTimeGenealogy] DATETIME NOT NULL,
PRIMARY KEY CLUSTERED ([GenealogyId] ASC),
CONSTRAINT [FK_aspnet_Genealogy_aspnet_Membership] FOREIGN KEY ([UserId]) REFERENCES [dbo].[aspnet_Membership] ([UserId])
);and
CREATE TABLE [dbo].[aspnet_Membership] (
[ApplicationId] UNIQUEIDENTIFIER NOT NULL,
[UserId] UNIQUEIDENTIFIER NOT NULL,
[Password] NVARCHAR (128) NOT NULL,
[PasswordFormat] INT DEFAULT ((0)) NOT NULL,
[PasswordSalt] NVARCHAR (128) NOT NULL,
[MobilePIN] NVARCHAR (16) NULL,
[Email] NVARCHAR (256) NULL,
[LoweredEmail] NVARCHAR (256) NULL,
[PasswordQuestion] NVARCHAR (256) NULL,
[PasswordAnswer] NVARCHAR (128) NULL,
[IsApproved] BIT NOT NULL,
[IsLockedOut] BIT NOT NULL,
[CreateDate] DATETIME NOT NULL,
[LastLoginDate] DATETIME NOT NULL,
[LastPasswordChangedDate] DATETIME NOT NULL,
[LastLockoutDate] DATETIME NOT NULL,
[FailedPasswordAttemptCount]Have you looked at the data (using SQL Server Management Studio) to find that the geneology table does not have the GUID in userid?
DECLARE @UserId uniqueidentifier
DECLARE @GenealogyId intIF ( @GenealogyId = +1 )
@GenealogyId will always be 0 (or null), you have just created it, so your update statement is wrong before it starts. I suggest you get the userid GUID before you insert the genealogy record.
Never underestimate the power of human stupidity RAH
-
Have you looked at the data (using SQL Server Management Studio) to find that the geneology table does not have the GUID in userid?
DECLARE @UserId uniqueidentifier
DECLARE @GenealogyId intIF ( @GenealogyId = +1 )
@GenealogyId will always be 0 (or null), you have just created it, so your update statement is wrong before it starts. I suggest you get the userid GUID before you insert the genealogy record.
Never underestimate the power of human stupidity RAH
Hi There, Thank you for the quick response, I changed the GenealogyId to = NULL. It still doesn't work, I have never heard of guid. How does it work and how is the code implemented? Can you explain? Look forward to hearing from you soon. Thanks