SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Database schema query - Phone number capturing


Database schema query - Phone number capturing

Author
Message
arthovs94
arthovs94
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 22

Hi,
I have been tasked with creating a schema to store phone numbers.

I've have looked through the various previous posts for guidance and the end result is below.
The main difference for us is that we capture Phone numbers in relation to different entities (customers, sales, patients, buyers, sellers,staff, Companies etc) .

To this end I created three tables Phone_Category ,Phone Numbers and Phone_link_tbl .

My question is ,is it better to have for example the staff_id,contact_id,company_id etc. stored in the Phone_link_tbl orto have a separate table for staff, companies and contacts each .

Thanks for the help !



[code language="Thursday 2 November 2017

16:09

createTable Phone_No_Category

(

Cat_ID INT PRIMARY KEY CLUSTERED NOT NULL

,Cat_Type varchar(255) not null



--constraint fkey foreign key (phone_no) references Phone_Numbers(Id)



)



createtable Phone_Numbers

(

Id int not null

,category_id int

,Area_code varchar(6)

,Phone_No varchar(11)

,International_code varchar(6)

constraint Pkey primary key(Id)

,constraint fkeycategoryphone foreign key (category_id) referencesPhone_No_category (Cat_ID)

)



Createtable phone_link_tbl

(

Phone_link_Idint not null

,Phone_idint

,staff_idint

,contact_idint

constraintPkeylink primary key (Phone_link_Id)

constraintfkeyPhone_num foreign key (Phone_Id) references Phone_Numbers (Id)

,constraintfkeystaff foreign key (staff_id) references intranetcontacts (Id)

,constraintfkeycontact foreign key (contact_id) references companies (comp_id)



)

"][/code]

Chris Harshman
Chris Harshman
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24164 Visits: 5965
If you already have separate tables for staff, contacts, and companies, then it probably makes logical sense to stay consistent and have 3 separate link tables. While it is possible to have 1 link table with the 3 different foreign keys, you'd probably also want a check constraint then to enforce that only 1 of the 3 foreign key columns is populated for each row. It would probably also be more confusing writing those joins with a single link table.
arthovs94
arthovs94
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 22
Thank you very much !
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search