简体   繁体   English

如何在SQL Server 2012数据库的一个表中分配许多列

[英]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.. 例如,因为我有2万个产品用于Apple,而华硕则有30k,MSI有40k ..因此,如果我在一张表中将苹果的所有列全部存储为70k条记录,则为NULL。

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. 另一个想法是,我每个制造商的表都很少,产品中的某些键指向Apple带有列的特定表。例如,键可以是apple1,apple2等。 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. 我正在为数据库使用SQL Server 2012。

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 然后,您可以选择类似Apple的信息,例如

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... 如果要比较规格,则带有产品数据的表格会更加复杂...

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一个SQL Server 2012数据库可以容纳多少张表? - How many tables can a single SQL Server 2012 database hold? SQL Server 2012,如果其中一列包含1个函数 - SQL Server 2012 if one of the columns contain 1 function 表的2列的SQL Server 2012检索属性 - SQL Server 2012 Retrieving Attributes for 2 Columns of a Table 如何从SQL Server 2012中的表的一个分区获取COUNT(*)? - How to get COUNT(*) from one partition of a table in SQL Server 2012? 如何从SQL Server的多个表中获取数据库列,然后按表名分组 - How to get database columns from more than one table in sql server and then group by table name 连续如何将SQL Server 2012中的数据从一个服务器数据库插入另一个服务器数据库 - Continuously How to insert data in SQL Server 2012 from one server database to another server database 如何在SQL Server 2012中将数据从另一个表的多个表行插入一个表行? - How to insert data into one table row from multiple table rows in another table in SQL Server 2012? 如何检测SQ​​L Server 2012数据库 - How to instrument a SQL Server 2012 database 如何在 SQL Server 2012 中解锁表? - How to unlock table in SQL Server 2012? SQL Server 2012将两个表中的列合并为一个 - SQL Server 2012 Joining columns from two tables into one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM