Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to know how i can make FormattedMembershipid as my primary key in tblPersonal table and also how to make it the foreign key in tblTransactions table. i tried this but didnt work please help me out

go

raiserror('creating Personal table....',0,1)
CREATE TABLE tblPersonal
(Membershipid int IDENTITY(1,1) ,
FormattedMembershipid AS ('COP/PIWC/ATOM/' + RIGHT ('000000' + CAST(Membershipid AS VARCHAR(6)),6)),
Regdate datetime,
Assemblys varchar(30)not null,
Surname varchar(100)not null,
Othername varchar(100)not null,
Gender varchar(10),
Nationality varchar(200))



go

raiserror('creating Transaction table....',0,1)
CREATE TABLE tblTransactions
(Transactionid int IDENTITY constraint pkTransid primary key clustered,
FormattedMembershipid varchar(300)foreign key (FormattedMembershipid) references tblPersonal (FormattedMembershipid), 
Datepaid datetime,
Surname varchar(100)not null,
Othername varchar(100)not null,
Assemblys varchar(30)not null)
Posted
Updated 21-Apr-14 1:50am
v2
Comments
Prasad Khandekar 21-Apr-14 8:21am    
As far as I know a computed column cannot be used as a DEFAULT or FOREIGN KEY constraint definition or with a NOT NULL constraint definition. My suggestion is to do this computation in your client code and store the computed value in the column. The column definition will be similar to other columns in your table.

Regards,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900