简体   繁体   中英

How distribute many columns in one table in SQL Server 2012 database

I am thinking about problem in our database.

I have one table for our products. It has few columns that it's for all products common. But products belongs to a manufacture. And each manufacture need some columns for the specification of product. So I am thinking about distributions for our table..

I think that have it all in one table is waste for memory. Because for example I have 20k products for Apple and 30k for Asus, 40k for MSI.. so if I have it all in one table for columns for apple will be NULL for 70k records..

Another idea was that I have few tables for each manufacture and in products has some key that pointing to specific table with columns for Apple.. for example key can be apple1, apple2 and so on. But with this idea it was quite difficult to show all products with theirs specific columns.

So I want to ask if someone thinking about this problem in database.

I am using SQL Server 2012 for our database.

Thanks for any help to this problem.

Databases are built to handle information as a collection of related sets ... and to use selection criteria to get you what you want to work with. You should design depending on how your information elements work .. something like:

  • Manufacturer table (with information that may be peculiar to a manufacturer (eg address, telephone, etc.)
  • Product table , with a foreign key reference to Manufacturer

You can then select information for, say, Apple with something like

select xxx 
from Product p, Manufacturer m 
where p.manufacturerID = m.manufacturerID and m.name = "Apple"

You can use such structure... It's just example...

If You want to compare specifications, table with product data will be more complex...

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM