SQL Server2005的XML数据类型之基础篇
一、 引言 如今,在SQL Server 2005中,XML成为第一流的 数据 类型 。借助于基于XML模式的强 类型 化支持和基于服务器端的XML 数据 校验功能,现在,开发者可以对存储的XML文档进行轻松地远程修改。 作为 数据 库开发者,许多人都必须大量地涉及XML。 如今,
一、 引言
如今,在SQL Server 2005中,XML成为第一流的数据类型。借助于基于XML模式的强类型化支持和基于服务器端的XML数据校验功能,现在,开发者可以对存储的XML文档进行轻松地远程修改。
作为数据库开发者,许多人都必须大量地涉及XML。
如今,在SQL Server 2005中,你能以一种新的数据类型的形式把XML存储在数据库中。
事实上,在SQL Server 2000中就已经包括了一些XML特征。其中,最关键的特征是使用FOR XML语句以XML形式返回结果。SQL Server 2005的功能则明显不同。在SQL Server 2005中,XML是一种真正的数据类型;这意味着,你可以使用XML作为表和视图中的列,XML可以用于T-SQL语句中或作为存储过程的参数。现在,你可以直接在数据库中存储、查询和管理XML文件。
更重要的是,现在你还能规定你的XML必须遵从的模式。
在SQL Server 2005中,除了提供机制以校验你的数据库中的XML类型之外,它还允许你描述要被存储的复杂数据类型并且提供一个引擎来强制施加这些规则。
二、 使用XML数据类型
其实,XML数据类型与SQL Server中的其它数据类型并不存在根本的区别。你可以把它用在使用任何普通SQL数据类型的地方。例如,下列语句创建一个XML变量并用一个XML填充它:
DECLARE @doc xml SELECT @doc = '<Team name="Braves" />' |
另外,你还可以使用一个查询和SQL Server的FOR XML语法来填充一个XML变量:
SELECT @doc = (SELECT * FROM Person.Contact FOR XML AUTO) |
XML数据类型不仅可以作为变量使用,也可以应用于表列中。你还能分配缺省值并且支持NOT NULL约束:
CREATE TABLE Team ( TeamID int identity not null, TeamDoc xml DEFAULT '<Team />' NOT NULL ) |
注意:SQL Server 2005的XML功能与SQL Server 2000中具有明显的不同。
把XML数据插入到表格中只需要用字符串形式的XML指定即可。
下列示例插入一组记录:
INSERT INTO Team (TeamDoc) VALUES (' <Team name="Braves"> <Players> <Pitcher name="John Smoltz" role="Closer"/> </Players> </Team>'); INSERT INTO Team (TeamDoc) VALUES (' <Team name="Red Sox"> <Players> <Pitcher name="Petro Martinez" role="Starter"/> </Players> </Team>'); |
当在SQL Server 2005中创建XML的实例时,唯一的转换是从一个字符串转换成一个XML类型。同样,沿着相反的方向,你只可以把XML类型转换成一个字符串类型。在text和ntext类型之间转换是不允许的。
三、 XML数据类型的限制
尽管在SQL Server 2005中XML数据类型就象许多其它数据类型一样对待,但是还存在一些如何使用它的具体限制。这些限制是:
? XML类型不能转换成text或ntext数据类型。
? 除了string类型,没有其它数据类型能够转换成XML。
? XML列不能应用于GROUP BY语句中。
? 分布式局部(partitioned)视图不能包含XML数据类型。
? sql_variant实例的使用不能把XML作为一种子类型。
? XML列不能成为主键或外键的一部分。
? XML列不能指定为唯一的。
? COLLATE子句不能被使用在XML列上。
? XML列不能加入到规则中。
? 唯一可应用于XML列的内置标量函数是ISNULL和COALESCE。没有任何其它内置标量函数支持使用XML类型。
? 表中最多只能拥有32个XML列。
? 具有XML列的表不能有一个超过15列的主键。
? 具有XML列的表不能有一个timestamp数据类型作为它们的主键的一部分。
? 存储在数据库中的XML仅支持128级的层次。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

FP8 and lower floating point quantification precision are no longer the "patent" of H100! Lao Huang wanted everyone to use INT8/INT4, and the Microsoft DeepSpeed team started running FP6 on A100 without official support from NVIDIA. Test results show that the new method TC-FPx's FP6 quantization on A100 is close to or occasionally faster than INT4, and has higher accuracy than the latter. On top of this, there is also end-to-end large model support, which has been open sourced and integrated into deep learning inference frameworks such as DeepSpeed. This result also has an immediate effect on accelerating large models - under this framework, using a single card to run Llama, the throughput is 2.65 times higher than that of dual cards. one

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

Last week, amid the internal wave of resignations and external criticism, OpenAI was plagued by internal and external troubles: - The infringement of the widow sister sparked global heated discussions - Employees signing "overlord clauses" were exposed one after another - Netizens listed Ultraman's "seven deadly sins" Rumors refuting: According to leaked information and documents obtained by Vox, OpenAI’s senior leadership, including Altman, was well aware of these equity recovery provisions and signed off on them. In addition, there is a serious and urgent issue facing OpenAI - AI safety. The recent departures of five security-related employees, including two of its most prominent employees, and the dissolution of the "Super Alignment" team have once again put OpenAI's security issues in the spotlight. Fortune magazine reported that OpenA

Last week, Microsoft airdropped WizardLM-2, an open source model called GPT-4 level. But I didn’t expect that it would be deleted immediately a few hours after it was posted. Some netizens suddenly discovered that WizardLM’s model weights and announcement posts had all been deleted and were no longer in the Microsoft collection. Apart from the mention of the site, no evidence could be found to prove that this was an official Microsoft project. The GitHub project homepage has become a 404. Project address: https://wizardlm.github.io/ Including the weight of the model on HF, all have disappeared... The whole network is full of confusion, why is WizardLM gone? However, the reason Microsoft did this was because the team forgot to "test" the model. Later, micro

Open-Sora has been quietly updated in the open source community. It now supports video generation up to 16 seconds, with resolutions up to 720p, and can handle text-to-image, text-to-video, image-to-video, and video-to-video of any aspect ratio. and the generation needs of infinitely long videos. Let's try it out. Generate a horizontal screen Christmas snow scene, post to B site and then generate a vertical screen, and use Douyin to generate a 16-second long video. Now everyone can have a screenwriting addiction. How to play? Guidance GitHub: https://github.com/hpcaitech/Open-Sora What’s even cooler is that Open-Sora is still all open source, including the latest model architecture, the latest model weights, multi-time/resolution/long-term
