使格式化的id作为我的表的主键和 [英] making formatted id as the primary key of my table and

查看:61
本文介绍了使格式化的id作为我的表的主键和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将FormattedMembershipid作为我在tblPersonal表中的主键,以及如何使它成为tblTransactions表中的外键。我试过这个,但没有工作,请帮帮我



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)

推荐答案

这篇关于使格式化的id作为我的表的主键和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆