Heim > Datenbank > MySQL-Tutorial > Hauptteil

SQL Server 2008中的稀疏列和列集

WBOY
Freigeben: 2016-06-07 17:39:46
Original
1222 Leute haben es durchsucht

这是两个新增的特性。 关于稀疏列的详细介绍,请参考 关于列集的详细介绍,请参考 我的总结如下 1. 稀疏列主要是为了提供对可空字段的更好一个存储机制,它可以节省空间(具体说它在真正空值的时候就不占空间),但也会带来一些性能方面的影响。所以要有所权

这是两个新增的特性。

关于稀疏列的详细介绍,请参考

关于列集的详细介绍,香港服务器,请参考  

我的总结如下

1. 稀疏列主要是为了提供对可空字段的更好一个存储机制,它可以节省空间(具体说它在真正空值的时候就不占空间),但也会带来一些性能方面的影响。所以要有所权衡。

稀疏列主要使用场景:一个实体有很多属性列,但很多属性都可能填不满。这在以前我们称为属性集问题。

稀疏列不是一个数据类型,它是一个列的属性而已。

2. 列集是可以定义所有稀疏列的集合。这是一个XML数据类型。如果为多个稀疏列定义了一个列集,那么针对这些列的修改,就既可以直接修改这些列,也可以通过一次性通过修改列集字段来完成。列集字段其实是一个计算字段。

下面来看一个例子

首先,看看如何使用稀疏列。这里的关键在于定义的时候使用SPARSE关键字

USE AdventureWorks GO CREATE TABLE DocumentStore (DocID int PRIMARY KEY, Title varchar(200) NOT NULL, ProductionSpecification varchar(20) SPARSE NULL, ProductionLocation smallint SPARSE NULL, MarketingSurveyGroup varchar(20) SPARSE NULL ) ; GO --插入数据是一模一样的 INSERT DocumentStore(DocID, Title, ProductionSpecification, ProductionLocation) VALUES (1, 'Tire Spec 1', 'AXZZ217', 27) GO INSERT DocumentStore(DocID, Title, MarketingSurveyGroup) VALUES (2, 'Survey 2142', 'Men 25 - 35') GO   然后,我们看看如何把列集与稀疏列进行结合使用 USE AdventureWorks; GO CREATE TABLE DocumentStoreWithColumnSet (DocID int PRIMARY KEY, Title varchar(200) NOT NULL, ProductionSpecification varchar(20) SPARSE NULL, ProductionLocation smallint SPARSE NULL, MarketingSurveyGroup varchar(20) SPARSE NULL, MarketingProgramID int SPARSE NULL, SpecialPurposeColumns XML COLUMN_SET FOR ALL_SPARSE_COLUMNS);--目前这里只是支持ALL_SPARSE_COLUMNS这个关键字,也就是说所有的稀疏列 GO --使用列集之后,服务器空间,既可以直接使用列集插入数据,也可以使用稀疏列本身插入数据 INSERT DocumentStoreWithColumnSet (DocID, Title, ProductionSpecification, ProductionLocation) VALUES (1, 'Tire Spec 1', 'AXZZ217', 27) GO INSERT DocumentStoreWithColumnSet (DocID, Title, MarketingSurveyGroup) VALUES (2, 'Survey 2142', 'Men 25 - 35') GO

 

INSERT DocumentStoreWithColumnSet (DocID, Title, SpecialPurposeColumns) VALUES (3, 'Tire Spec 2', 'AXW9R41138') GO 有意思的是,此时如果再以SELECT *的语法查询该表的话,那些稀疏列默认是不会被返回的,而只是返回列集

image

当然啦,如果还是想返回稀疏列本身的内容,我们可以通过下面的语法 SELECT DocID, Title, ProductionSpecification, ProductionLocation FROM DocumentStoreWithColumnSet WHERE ProductionSpecification IS NOT NULL ;

image

至于更新,和插入一样,两种方式都是可以的,且效果一样

,香港服务器
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!