如何创建具有从同一表中的2个字段分解的字段值的表? [英] How to create a table with a field value decomposed from 2 fields in the same table ?

查看:76
本文介绍了如何创建具有从同一表中的2个字段分解的字段值的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想做的事情:

如果您有一个包含有关abt订户信息的表,并且该表具有以下字段(例如Canda中的订户,订户号= 514-XXXXXXX):

1-前缀(指操作员id,指向包含该id的其他表的外键,该ID的相应前缀和描述,例如:1,514,CanadaPhone)

2位号码(其余的订户号码,如canda Ex = XXXXXXX)

我想要该表中的第三个字段,其中包含从前缀和编号组合而成的subscriber_id,但我希望它能自动完成.

如果您更改前缀,则用户ID将被更改;如果您更改了编号,则用户ID将被自动更改

请记住,我希望该订户ID成为表的主键.

是否适用?
如果适用,请帮助我.

提前thnx

Here what i want to do :

if u have a table containing information abt subscribers and that table got the following fields (example in Canda , subscriber number = 514 - XXXXXXX):

1- prefix ( refers to Operator id , foreign key to different table containing the id , the corresponding prefix and description of that id , EX: 1,514,CanadaPhone)

2- number ( rest of subscriber number as in canda Ex= XXXXXXX)

what i want a third field in that table which contains the subscriber_id combined from prefix and number but i want it to be done automatically .

if u change prefix the subscriber id will be changed and if u change the number the subscriber id will be changed AUTOMATICALLY

remember that i want that subscriber id to be the primary key to the table.

is it applicable or not ?
if it is applicable plz help me .

thnx in advance

推荐答案

您需要的是 TRIGGER .

阅读此内容: MSDN:SQL创建触发器 [数据规范化 [ ^ ]),您应该避免这样做.如果需要,可以随时在检索时将列值连接起来.
What you need is a TRIGGER.

Read this: MSDN: SQL CREATE TRIGGER[^]

You can use trigger to automatically insert the third coloumn value as column 1 & 2 concatenated value.

Though, from DB design point of view (looking at Data Normalization[^]), you should avoid doing such thing. If needed at any time, while retriving you can concatenate the column values.


这篇关于如何创建具有从同一表中的2个字段分解的字段值的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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