Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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.
 
Share this answer
 

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