Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server normalization tactic: varchar vs int Identity

I'm just wondering what the optimal solution is here.

Say I have a normalized database. The primary key of the whole system is a varchar. What I'm wondering is should I relate this varchar to an int for normalization or leave it? It's simpler to leave as a varchar, but it might be more optimal

For instance I can have

People
======================
name      varchar(10)   
DoB       DateTime    
Height    int  

Phone_Number
======================
name      varchar(10)   
number    varchar(15)

Or I could have

People
======================
id        int Identity   
name      varchar(10)   
DoB       DateTime  
Height    int  

Phone_Number
======================
id        int   
number    varchar(15)  

Add several other one-to-many relationships of course.

What do you all think? Which is better and why?

like image 767
theo Avatar asked Aug 09 '26 12:08

theo


1 Answers

I believe that the majority of people who have developed any significant sized real world database applications will tell you that surrogate keys are the only realistic solution.
I know the academic community will disagree but that is the difference between theoretical purity and practicality.

Any reasonable sized query that has to do joins between tables that use non-surrogate keys where some tables have composite primary keys quickly becomes unmaintainable.

like image 175
Darrel Miller Avatar answered Aug 11 '26 04:08

Darrel Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!