Jinghao Liu (刘劲浩)'s BLOG

一个专门有关SQL Server的中文博客. 主要面向中国的SQL Server用户. 侧重于介绍的SQL Server 2005在XML方面的功能.也会尽力解答其他SQL相关问题.

  • TechEd 2008: 演示SQL脚本 for "全面整合的SQL Server 2008 全文本搜索"

    下面的演示在两个演讲中都用到了。因为不能把所用文本数据直接给出,我提供了链接。希望能为大家学习和了解SQL2008 fulltext有帮助。

     

    --------------------------------------------------

    -- Create fulltext demo database

    --------------------------------------------------

    use master

    go

    DROP DATABASE ftDemoDatabase

    go

    CREATE DATABASE ftDemoDatabase

    go

    use ftDemoDatabase

    go

     

    --------------------------------------------------

    -- Create fulltext catalog

    --------------------------------------------------

    CREATE FULLTEXT CATALOG ftDemoCatalog AS DEFAULT;

    go

     

    --------------------------------------------------

    -- Create tables

    --------------------------------------------------

    CREATE TABLE tblDemoBook (

      id int primary key,

      title nvarchar(100),

      author nvarchar(100),

      comment nvarchar(max)

    )

    go

    CREATE TABLE tblDemoContent (

      id int identity,

      bookid int foreign key references tblDemoBook(id),

      chapter int,

      content nvarchar(max),

      fileName varchar(200), 

      constraint pk_tbl_DemoContent primary key (id)

    )

    go

     

    -------------------------------------------------------------------------

    -- Insert data into tables

    -- You can find the books used in this demo from following links. 

    -- You need to change file paths below to match yours

    -- 雪白血红: http://www.yifan.net/novels/wars/xuehong/xuehong.html

    -- 两晋演义: http://www.yifan.net/novels/history/liangjin/liangjin.html

    -------------------------------------------------------------------------

     INSERT tblDemoBook values

    (2, N'雪白血红', N'张正隆', N'报告文学:-1948内战中的东北战场'), (2, N'两晋演义', N'蔡东藩', N'历史小说')

    go

    INSERT tblDemoContent(bookid, chapter, content, fileName) values

    (1, 1,(select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong01.html', SINGLE_CLOB) as T(c)), 'xuehong01.html'),

    (1, 2, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong02.html', SINGLE_CLOB) as T(c)), 'xuehong02.html'),

    (1, 3, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong03.html', SINGLE_CLOB) as T(c)), 'xuehong03.html'),

    (1, 4, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong04.html', SINGLE_CLOB) as T(c)), 'xuehong04.html'),

    (1, 5, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong05.html', SINGLE_CLOB) as T(c)), 'xuehong05.html'),

    (1, 6, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong06.html', SINGLE_CLOB) as T(c)), 'xuehong06.html'),

    (1, 7, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong07.html', SINGLE_CLOB) as T(c)), 'xuehong07.html'),

    (1, 8, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong08.html', SINGLE_CLOB) as T(c)), 'xuehong08.html'),

    (1, 9, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong09.html', SINGLE_CLOB) as T(c)), 'xuehong09.html'),

    (1, 10, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong10.html', SINGLE_CLOB) as T(c)), 'xuehong10.html'),

    (1, 11, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong11.html', SINGLE_CLOB) as T(c)), 'xuehong11.html'),

    (1, 12, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong12.html', SINGLE_CLOB) as T(c)), 'xuehong12.html'),

    (1, 13, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong13.html', SINGLE_CLOB) as T(c)), 'xuehong13.html'),

    (1, 14, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong14.html', SINGLE_CLOB) as T(c)), 'xuehong14.html'),

    (1, 15, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong15.html', SINGLE_CLOB) as T(c)), 'xuehong15.html'),

    (1, 16, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong16.html', SINGLE_CLOB) as T(c)), 'xuehong16.html'),

    (1, 17, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong17.html', SINGLE_CLOB) as T(c)), 'xuehong17.html'),

    (1, 18, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong18.html', SINGLE_CLOB) as T(c)), 'xuehong18.html'),

    (1, 19, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong19.html', SINGLE_CLOB) as T(c)), 'xuehong19.html'),

    (1, 20, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong20.html', SINGLE_CLOB) as T(c)), 'xuehong20.html'),

    (1, 22, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong21.html', SINGLE_CLOB) as T(c)), 'xuehong21.html'),

    (1, 22, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong22.html', SINGLE_CLOB) as T(c)), 'xuehong22.html'),

    (1, 23, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong23.html', SINGLE_CLOB) as T(c)), 'xuehong23.html'),

    (1, 24, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong24.html', SINGLE_CLOB) as T(c)), 'xuehong24.html'),

    (1, 25, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong25.html', SINGLE_CLOB) as T(c)), 'xuehong25.html'),

    (1, 26, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong26.html', SINGLE_CLOB) as T(c)), 'xuehong26.html'),

    (1, 27, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong27.html', SINGLE_CLOB) as T(c)), 'xuehong27.html'),

    (1, 28, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong28.html', SINGLE_CLOB) as T(c)), 'xuehong28.html'),

    (1, 29, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong29.html', SINGLE_CLOB) as T(c)), 'xuehong29.html'),

    (1, 30, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong30.html', SINGLE_CLOB) as T(c)), 'xuehong30.html'),

    (1, 32, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong31.html', SINGLE_CLOB) as T(c)), 'xuehong31.html'),

    (1, 32, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong32.html', SINGLE_CLOB) as T(c)), 'xuehong32.html'),

    (1, 33, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong33.html', SINGLE_CLOB) as T(c)), 'xuehong33.html'),

    (1, 34, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong34.html', SINGLE_CLOB) as T(c)), 'xuehong34.html'),

    (1, 35, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong35.html', SINGLE_CLOB) as T(c)), 'xuehong35.html'),

    (1, 36, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong36.html', SINGLE_CLOB) as T(c)), 'xuehong36.html'),

    (1, 37, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\xuehong\xuehong37.html', SINGLE_CLOB) as T(c)), 'xuehong37.html')

    go

    INSERT tblDemoContent(bookid, chapter, content, fileName) values

    (2, 1, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin01.html', SINGLE_CLOB) as T(c)), 'liangji01.html'),

    (2, 2, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin02.html', SINGLE_CLOB) as T(c)), 'liangji02.html'),

    (2, 3, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin03.html', SINGLE_CLOB) as T(c)), 'liangji03.html'),

    (2, 4, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin04.html', SINGLE_CLOB) as T(c)), 'liangji04.html'),

    (2, 5, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin05.html', SINGLE_CLOB) as T(c)), 'liangji05.html'),

    (2, 6, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin06.html', SINGLE_CLOB) as T(c)), 'liangji06.html'),

    (2, 7, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin07.html', SINGLE_CLOB) as T(c)), 'liangji07.html'),

    (2, 8, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin08.html', SINGLE_CLOB) as T(c)), 'liangji08.html'),

    (2, 9, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin09.html', SINGLE_CLOB) as T(c)), 'liangji09.html'),

    (2, 10, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin10.html', SINGLE_CLOB) as T(c)), 'liangji10.html'),

    (2, 12, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin11.html', SINGLE_CLOB) as T(c)), 'liangji11.html'),

    (2, 12, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin12.html', SINGLE_CLOB) as T(c)), 'liangji12.html'),

    (2, 13, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin13.html', SINGLE_CLOB) as T(c)), 'liangji13.html'),

    (2, 14, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin14.html', SINGLE_CLOB) as T(c)), 'liangji14.html'),

    (2, 15, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin15.html', SINGLE_CLOB) as T(c)), 'liangji15.html'),

    (2, 16, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin16.html', SINGLE_CLOB) as T(c)), 'liangji16.html'),

    (2, 17, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin17.html', SINGLE_CLOB) as T(c)), 'liangji17.html'),

    (2, 18, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin18.html', SINGLE_CLOB) as T(c)), 'liangji18.html'),

    (2, 19, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin19.html', SINGLE_CLOB) as T(c)), 'liangji19.html'),

    (2, 20, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin20.html', SINGLE_CLOB) as T(c)), 'liangji20.html'),

    (2, 22, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin21.html', SINGLE_CLOB) as T(c)), 'liangji21.html'),

    (2, 22, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin22.html', SINGLE_CLOB) as T(c)), 'liangji22.html'),

    (2, 23, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin23.html', SINGLE_CLOB) as T(c)), 'liangji23.html'),

    (2, 24, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin24.html', SINGLE_CLOB) as T(c)), 'liangji24.html'),

    (2, 25, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin25.html', SINGLE_CLOB) as T(c)), 'liangji25.html'),

    (2, 26, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin26.html', SINGLE_CLOB) as T(c)), 'liangji26.html'),

    (2, 27, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin27.html', SINGLE_CLOB) as T(c)), 'liangji27.html'),

    (2, 28, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin28.html', SINGLE_CLOB) as T(c)), 'liangji28.html'),

    (2, 29, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin29.html', SINGLE_CLOB) as T(c)), 'liangji29.html'),

    (2, 30, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin30.html', SINGLE_CLOB) as T(c)), 'liangji30.html'),

    (2, 32, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin31.html', SINGLE_CLOB) as T(c)), 'liangji31.html'),

    (2, 32, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin32.html', SINGLE_CLOB) as T(c)), 'liangji32.html'),

    (2, 33, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin33.html', SINGLE_CLOB) as T(c)), 'liangji33.html'),

    (2, 34, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin34.html', SINGLE_CLOB) as T(c)), 'liangji34.html'),

    (2, 35, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin35.html', SINGLE_CLOB) as T(c)), 'liangji35.html'),

    (2, 36, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin36.html', SINGLE_CLOB) as T(c)), 'liangji36.html'),

    (2, 37, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin37.html', SINGLE_CLOB) as T(c)), 'liangji37.html'),

    (2, 38, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin38.html', SINGLE_CLOB) as T(c)), 'liangji38.html'),

    (2, 39, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin39.html', SINGLE_CLOB) as T(c)), 'liangji39.html'),

    (2, 40, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin40.html', SINGLE_CLOB) as T(c)), 'liangji40.html'),

    (2, 42, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin41.html', SINGLE_CLOB) as T(c)), 'liangji41.html'),

    (2, 42, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin42.html', SINGLE_CLOB) as T(c)), 'liangji42.html'),

    (2, 43, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin43.html', SINGLE_CLOB) as T(c)), 'liangji43.html'),

    (2, 44, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin44.html', SINGLE_CLOB) as T(c)), 'liangji44.html'),

    (2, 45, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin45.html', SINGLE_CLOB) as T(c)), 'liangji45.html'),

    (2, 46, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin46.html', SINGLE_CLOB) as T(c)), 'liangji46.html'),

    (2, 47, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin47.html', SINGLE_CLOB) as T(c)), 'liangji47.html'),

    (2, 48, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin48.html', SINGLE_CLOB) as T(c)), 'liangji48.html'),

    (2, 49, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin49.html', SINGLE_CLOB) as T(c)), 'liangji49.html'),

    (2, 50, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin50.html', SINGLE_CLOB) as T(c)), 'liangji50.html'),

    (2, 52, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin51.html', SINGLE_CLOB) as T(c)), 'liangji51.html'),

    (2, 52, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin52.html', SINGLE_CLOB) as T(c)), 'liangji52.html'),

    (2, 53, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin53.html', SINGLE_CLOB) as T(c)), 'liangji53.html'),

    (2, 54, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin54.html', SINGLE_CLOB) as T(c)), 'liangji54.html'),

    (2, 55, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin55.html', SINGLE_CLOB) as T(c)), 'liangji55.html'),

    (2, 56, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin56.html', SINGLE_CLOB) as T(c)), 'liangji56.html'),

    (2, 57, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin57.html', SINGLE_CLOB) as T(c)), 'liangji57.html'),

    (2, 58, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin58.html', SINGLE_CLOB) as T(c)), 'liangji58.html'),

    (2, 59, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin59.html', SINGLE_CLOB) as T(c)), 'liangji59.html'),

    (2, 60, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin60.html', SINGLE_CLOB) as T(c)), 'liangji60.html'),

    (2, 62, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin61.html', SINGLE_CLOB) as T(c)), 'liangji61.html'),

    (2, 62, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin62.html', SINGLE_CLOB) as T(c)), 'liangji62.html'),

    (2, 63, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin63.html', SINGLE_CLOB) as T(c)), 'liangji63.html'),

    (2, 64, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin64.html', SINGLE_CLOB) as T(c)), 'liangji64.html'),

    (2, 65, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin65.html', SINGLE_CLOB) as T(c)), 'liangji65.html'),

    (2, 66, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin66.html', SINGLE_CLOB) as T(c)), 'liangji66.html'),

    (2, 67, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin67.html', SINGLE_CLOB) as T(c)), 'liangji67.html'),

    (2, 68, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin68.html', SINGLE_CLOB) as T(c)), 'liangji68.html'),

    (2, 69, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin69.html', SINGLE_CLOB) as T(c)), 'liangji69.html'),

    (2, 70, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin70.html', SINGLE_CLOB) as T(c)), 'liangji70.html'),

    (2, 72, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin71.html', SINGLE_CLOB) as T(c)), 'liangji71.html'),

    (2, 72, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin72.html', SINGLE_CLOB) as T(c)), 'liangji72.html'),

    (2, 73, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin73.html', SINGLE_CLOB) as T(c)), 'liangji73.html'),

    (2, 74, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin74.html', SINGLE_CLOB) as T(c)), 'liangji74.html'),

    (2, 75, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin75.html', SINGLE_CLOB) as T(c)), 'liangji75.html'),

    (2, 76, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin76.html', SINGLE_CLOB) as T(c)), 'liangji76.html'),

    (2, 77, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin77.html', SINGLE_CLOB) as T(c)), 'liangji77.html'),

    (2, 78, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin78.html', SINGLE_CLOB) as T(c)), 'liangji78.html'),

    (2, 79, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin79.html', SINGLE_CLOB) as T(c)), 'liangji79.html'),

    (2, 80, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin80.html', SINGLE_NCLOB) as T(c)), 'liangji80.html'),

    (2, 82, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin81.html', SINGLE_CLOB) as T(c)), 'liangji81.html'),

    (2, 82, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin82.html', SINGLE_CLOB) as T(c)), 'liangji82.html'),

    (2, 83, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin83.html', SINGLE_CLOB) as T(c)), 'liangji83.html'),

    (2, 84, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin84.html', SINGLE_CLOB) as T(c)), 'liangji84.html'),

    (2, 85, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin85.html', SINGLE_CLOB) as T(c)), 'liangji85.html'),

    (2, 86, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin86.html', SINGLE_CLOB) as T(c)), 'liangji86.html'),

    (2, 87, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin87.html', SINGLE_CLOB) as T(c)), 'liangji87.html'),

    (2, 88, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin88.html', SINGLE_CLOB) as T(c)), 'liangji88.html'),

    (2, 89, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin89.html', SINGLE_CLOB) as T(c)), 'liangji89.html'),

    (2, 90, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin90.html', SINGLE_CLOB) as T(c)), 'liangji90.html'),

    (2, 92, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin91.html', SINGLE_CLOB) as T(c)), 'liangji91.html'),

    (2, 92, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin92.html', SINGLE_CLOB) as T(c)), 'liangji92.html'),

    (2, 93, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin93.html', SINGLE_CLOB) as T(c)), 'liangji93.html'),

    (2, 94, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin94.html', SINGLE_CLOB) as T(c)), 'liangji94.html'),

    (2, 95, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin95.html', SINGLE_CLOB) as T(c)), 'liangji95.html'),

    (2, 96, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin96.html', SINGLE_CLOB) as T(c)), 'liangji96.html'),

    (2, 97, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin97.html', SINGLE_CLOB) as T(c)), 'liangji97.html'),

    (2, 98, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin98.html', SINGLE_CLOB) as T(c)), 'liangji98.html'),

    (2, 99, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin99.html', SINGLE_CLOB) as T(c)), 'liangji99.html'),

    (2, 100, (select c from openrowset(bulk N'C:\Public\eBooks\YiFanShuKu\liangjin\liangjin100.html', SINGLE_CLOB) as T(c)), 'liangji100.html')

    go

     

    --------------------------------------------------

    -- Create fulltext index on textual column

    --------------------------------------------------

    --drop fulltext index on tblDemoContent

    --go

    CREATE FULLTEXT INDEX ON tblDemoContent(content)

    --(content LANGUAGE 'Simplified Chinese')

       KEY INDEX pk_tbl_DemoContent

    GO

     

    --------------------------------------------------

    -- Run a fulltext query

    --------------------------------------------------

    select c.*

    from tblDemoContent c, tblDemoBook b

    where c.bookid = b.id

      and b.title = '雪白血红'

      and contains(c.content, N'杜聿明')

    go

     

    ---------------------------------------------------

    -- Example of mixed relational and fulltext queries

    ---------------------------------------------------

    select * from tblDemoContent

    where contains(content, N'林彪')

      and chapter < 6

    go

    select * from tblDemoContent

    where contains(content, N'林彪')

      and fileName like 'xuehong08.html'

    go

     

    --------------------------------------------------

    -- Query directly about keywords and its frequency

    --------------------------------------------------

    select *

    from sys.dm_fts_index_keywords(DB_ID('ftDemoDatabase'), OBJECT_ID('dbo.tblDemoContent'))

    where display_term = N'林彪'

    go

    select *

    from sys.dm_fts_index_keywords_by_document(DB_ID('ftDemoDatabase'), OBJECT_ID('dbo.tblDemoContent'))

    go

     

    -- list all languages supported in SQL

    select * from sys.syslanguages

    go

  • TechEd 2008: 有关空间数据(Spatial), Datatimeoffset, 文件流(Filestream), 稀疏列(Sparse Column)的SQL演示脚本

    DAT 331: 实例演示:用SQL Server 2008开发一个地理信息处理系统

     

    -----------------------------------------------------------------

    -- 空间数据的处理

    -----------------------------------------------------------------

    --

    declare @point Geometry

    set @point = Geometry::Parse('POINT(0 0)')

    select @point.ToString(), @point.STBuffer(10)

    go

    -- 多点

    declare @mpoint Geometry

    set @mpoint = Geometry::Parse('MULTIPOINT(0 0, 0 80, 80 80, 0 80)')

    select @mpoint.ToString(), @mpoint.STBuffer(2)

    go

    -- 多边型

    -- 1) 至少四个不同点

    -- 2) 起点和终点一致

    declare @polygon Geometry

    set @polygon = Geometry::Parse('POLYGON((0 0, 0 40, 40 40, 40 0, 0 0))')

    select @polygon.ToString(), @polygon

    go

    DECLARE @g geography;

    SET @g = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326);

    select @g.STBuffer(0.01)

    SELECT @g.BufferWithTolerance(1, .5, 0).ToString();

     

    -- 多个多边型

    declare @mpolygon Geometry

    set @mpolygon = Geometry::Parse('MULTIPOLYGON(((0 0, 0 80, 80 80, 0 80, 0 0), (-1 -1, -2 -10, -10 -2, -1 -1)))')

    select @mpolygon.ToString(), @mpolygon

    go

    -- 线: 至少两个不同点

    declare @line Geometry

    set @line = Geometry::Parse('LINESTRING(0 0, 0 0, 0 0)')

    select @line.ToString()

    select @line.STNumPoints()

    go

    -- 多线

    -- Note: Polygon is LingString too

    declare @mline Geometry

    set @mline = Geometry::Parse('MULTILINESTRING((0 0, 5 5, 0 0), (0 0, 0 80, 80 80, 0 80, 0 0))')

    select @mline.ToString()

    go

    -- 空间集GeometryCollection

    declare @gc Geometry

    set @gc = Geometry::Parse('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0, 5 5), POLYGON((0 0, 0 80, 80 80, 0 80, 0 0)))')

    select @gc.ToString()

    go

    -- 一个使用实例

    DECLARE @g geometry = geometry::STGeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))', 0);

    DECLARE @h geometry = geometry::STGeomFromText('POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))', 0);

    --DECLARE @h geometry = geometry::STGeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))', 0);

    SELECT @g.STContains(@h);

    SELECT @h.STContains(@g)

    go

     

    -----------------------------------------------------------------

    -- 有关日期、时间的新数据类型

    -----------------------------------------------------------------

    if exists( select * from sys.tables where name = 't1' )

      drop table t1

     go

    CREATE TABLE t1 (

        c1 DATE,

        c2 TIME(3),

        c3 DATETIME2(7) NOT NULL DEFAULT GETDATE(),

        c4 DATETIMEOFFSET CHECK (c4 < CAST(GETDATE() AS DATETIMEOFFSET(0)))

    )

    go

    INSERT INTO t1 VALUES ('0001-01-01', '23:59:59',

        '0001-12-21 23:59:59.1234567',

        '2008-10-10 23:59:59.1234567 -07:00')

    go

    SELECT c4 cDateTimeOffset,

           DATEPART(TZOFFSET, c4) cTimeZone,

           DATEPART(ISO_WEEK, c4) cWeek,

           DATEPART(MICROSECOND, c4) cMicrosecond

    FROM t1

    go

    -- 通过改变本机的时区, 观察SYSDATETIMEOFFSET不同的结果

    SELECT SYSDATETIME(), SYSUTCDATETIME(), SYSDATETIMEOFFSET()

    go

     

    -----------------------------------------------------------------

    -- 文件流(Filestream). 注意: 需要先激活这一功能。

    -----------------------------------------------------------------

    use master

    go

    -- enable filestream

    sp_configure 'filestream_access_level', 2

    reconfigure with override

    go

     

    if exists( select * from sys.databases where name = 'MyFSDB' )

      drop database MyFSDB

    go

    -- 注意: 改变下面文件路径以适应你的系统

    create database MyFSDB

    on primary

    ( name = MyFSDB_dat,

      filename = 'c:\sqldata\FS\MyFSDB_dat.mdf' ),

    filegroup filestreamgroup contains filestream

    ( name = MyFSDB_fsGroup,

      filename = 'c:\sqldata\FS\MyFSDB_fsGroup' )

    log on

    ( name = MyFSDB_log,

      filename = 'c:\sqldata\FS\MyFSDB_log.ldf' )

    go

    use MyFSDB

    go

     

    -- create table with column on filestream

    CREATE TABLE demoFilestream (

    fileID UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL primary key,

    fileName NVARCHAR(256),

    officeFile VARBINARY(MAX) FILESTREAM)

    filestream_on filestreamgroup

    go

    -- insert NULL value

    insert demoFilestream values(newid(), NULL, NULL)

    -- insert empty value

    insert demoFilestream values(newid(), 'EmptyFile', cast('' as varbinary(max)))

    -- insert some value

    insert demoFilestream values(newid(), 'HelloWorld.doc', cast(N'Hello World! 世界,你好!' as varbinary(max)))

    go

    -- take a look the data

    SELECT *, datalength(officeFile)

    , cast(officeFile as nvarchar(max))

    , officeFile.PathName()

    from demoFilestream

    go

     

    -----------------------------------------------------------------

    -- 稀疏列Sparse Column

    -----------------------------------------------------------------

    drop table tblTestBig

    go

    -- create table with a set of sparse column, and a column set

    create table tblTestBig

    ( c1 int,

      c2 int sparse,

      c3 varchar(8000) sparse,

      c4 varchar(50) sparse,

      cs xml column_set for all_sparse_columns

    )

    go

    -- insert a row

    insert tblTestBig (c1, c2, c3, c4) values(

    120, null,

    '12345678901234567890123456789012345678901234567890',

    'abcdefghijklmnopqrstuvwxyz')

    go

    -- select from it

    select * from tblTestBig

    go

    -- add another column

    alter table tblTestbig add c5 int sparse

    go

    -- select again and see the difference

    select * from tblTestBig

    go

    -- insert another row

    insert tblTestBig (c1, c2, c3, c4, c5) values(

    120, null,

    '12345678901234567890123456789012345678901234567890',

    'abcdefghijklmnopqrstuvwxyz',

    '100')

    go

    -- select from it

    select * from tblTestBig

    go

     

    -----------------------------------------------------------------

    -- 全文本搜索的演示将在下一帖中展示。

    -----------------------------------------------------------------

  • 一个小实验

    好久没写了。这次为了实现在Teched 2008中许下的诺言,重做冯妇。先写一个小贴试验一下。
  • 吉姆•格雷失踪了!

    吉姆·失踪了!” 

    当我看到同事转发来的email的题目时,我真有点不相信自己的眼睛.  读完了那篇Mercury News的报道, 经过了初期震惊后的理性告诉我: 这是因为我不愿意相信.

    大部分SQL Server team 的人都是那种只信科学不信神的 hard core geeks.  但我想很多人可能都象我一样,在心里暗中祈祷奇迹发生.  都是在RDBMS这个圈子里的人.  这里有太多吉姆的朋友,前同事, 和粉丝.  另外作为微软的一员,我们知道公司失去了唯一的图灵奖获得者L.

    吉姆是分布式计算技术(distributed computing )”先知级鼓吹者(区别于事后诸葛亮们).  这是一篇他在1985年写的文章: http://research.microsoft.com/~gray/papers/TandemTR85.4_AnApproachToDecentralizedComputerSystems.pdf.  懂计算机且置身于Web2.0时代的人读了这篇东西,会明白为什么他得计算机领域中的诺贝尔.

    我有幸和吉姆·雷有过一次近距离的接触. 2005年初,我们SQL 2005 XML项目组请他来review 我们做的XML features. 我们五,六个人为他演示和讲解了SQL 2005 XML Datatype, XML Index, XML Schema Collection, XQuery, FOR XML等功能. 他给我们提了一些有关应用方面的建议. 给我留下很深印象的是: 这位六十岁左右的老人敏捷的思路和对新东西无止境的好奇心. 我从小在研究大院长大. 来美国前也在研究单位工作过. 到微软后更是接触了太多聪明绝顶的中国人. 坦率的讲,我就从来没有碰见过他这样功成名就后的依然科学家的科学家. 我到是见识过很多开公司发财的前科学家,热衷于政治的前科学家,当了德育导师的前科学家,当然更多的是当了VP 或各种 % 长的前科学家. 让我真佩服钱钟书在围城里总结的:”外国科学进步,中国科学家进爵L.

    当我回家对太太提及吉姆出海失踪一事时, 她评论说有钱玩这种帆船,飞机有什么好? 约翰.丹佛和小肯尼迪就是玩飞机死的.  这又有一个玩船的.”.  太太说得一点没错.  但我还是挺羡慕吉姆的.  人都有一死.  如果能干着自己最享受的事走向终点,不亦乐呼!

    Have Fun, Jim!

    P.S: 有关这件事的中文报道见: http://www.thefirst.cn/82/2007-02-02/44683.htm

  • SQL2005对XSD的支持更丰富了数据建模的方法

    在SQL2005中,有一个新的顶级对象(top level object)被加入: XML架构集合(XML Schema Collection).  它提供给用户贮存XSD (XML Schema Definition)并用之验证特定XML格式的能力. 更重要的是,它提供了一种可更丰富描述数据模型的方法

    举例:
    create xml schema collection xsdPurchaseOrder as
    N'<schema targetNamespace="http://www.example.com/IPO" xmlns="http://www.w3.org/2001/XMLSchema"
     xmlns:ipo="http://www.example.com/IPO" elementFormDefault="qualified">

     <annotation>
       <documentation xml:lang="zh-Hans">
      为国际订货单据定义的各种地址格式
      Copyright 2000 Example.com. All rights reserved.
       </documentation>
     </annotation>

     <!-- 一般地址 -->
     <complexType name="Address">
       <sequence>
         <element name="name" type="string"/>
         <element name="street" type="string"/>
         <element name="city" type="string"/>
       </sequence>
     </complexType>

     <!-- 美国地址附加信息 -->
     <complexType name="USAddress">
       <complexContent>
         <extension base="ipo:Address">
           <sequence>
             <element name="state" type="ipo:USState"/>
             <element name="zip" type="positiveInteger"/>
           </sequence>
         </extension>
       </complexContent>
     </complexType>

     <!-- 中国地址附加信息 -->
     <complexType name="CNAddress">
       <complexContent>
         <extension base="ipo:Address">
           <sequence>
             <element name="省" type="ipo:CNProvince"/>
           <element name="邮编" type="positiveInteger"/>
        </sequence>
      </extension>
       </complexContent>
     </complexType>

     <!-- 定义美国州的数据类型 -->
     <simpleType name="USState">
       <restriction base="string">
         <enumeration value="AK"/>
         <enumeration value="AL"/>
         <enumeration value="AR"/>
         <!-- and so on ... -->
         <enumeration value="PA"/>
       </restriction>
     </simpleType>

     <!-- 定义中国省的数据类型 -->
     <simpleType name="CNProvince">
       <restriction base="string">
         <enumeration value="湖南"/>
         <enumeration value="湖北"/>
         <enumeration value="辽宁"/>
         <!-- and so on ... -->
         <enumeration value="江苏"/>
       </restriction>
     </simpleType>

     <!-- 根元素 -->
     <element name="purchaseOrder" type="ipo:PurchaseOrderType"/>

     <element name="comment" type="string"/>

     <complexType name="PurchaseOrderType">
      <sequence>
       <element name="shipTo" type="ipo:Address"/>
       <element name="billTo" type="ipo:Address"/>
       <element ref="ipo:comment" minOccurs="0"/>
       <!-- 为了简化我剩去了items的复杂定义 -->
       <element name="items" type="string"/>
      </sequence>
      <attribute name="orderDate" type="date"/>
     </complexType>
    </schema>'
    go

    针对上述格式,我们可将下面的订单存入数据库中带有此架构集合的XML列中. SQL Server将对要存入的XML进行验证(validate),确保数据的格式. 这实际上就提供了新的数据建模方法.

    create table tbl_Orders( id int, PurchaseOrder xml(xsdPurchaseOrder) )
    insert tbl_Orders value( 1,
    N'<purchaseOrder xmlns="http://www.example.com/IPO" orderDate="2005-10-30">
     <shipTo>
      <name>兴业公司</name>
       <street>兴业路十五号</street>
       <city>无锡</city>
       <省>江苏</省>
       <邮编>12345</邮编>
     </shipTo>
     <billTo>
      <name>ABC Corp</name>
      <street>1710 Madison Ave.</street>
      <city>Jamesville</city>
      <state>PA</state>
      <zip>98000</zip>
     </billTo>
     <comment>ABC Corp 购买一批组件并直接寄送兴业公司组装</comment>
     <items>541045系列组件</items>
    </purchaseOrder>' )
    go

    在上述例子中,我们定义了不同格式的地址并用xs:enumeration为<省>和<state>约束了数值范围.

  • XML提供新的数据建模方法

    W3C的专家们刚开始筹划XML(eXtensible Markup Language) 的标准时,他们的目的是发明一种比HTML更好得标识语言:Originally designed to meet the challenges of large-scale electronic publishing …”(http://www.w3.org/XML/)。没有想到最终结果却是为互联网上的数据传输提供了一个好办法。

     

    <Customer CustomerID="ALFKI" CompanyName="Alfreds Futterkiste" ContactName="Maria Anders" Phone="030-0074321">

      <Order OrderID="10643" OrderDate="1997-08-25T00:00:00">

        <OrderDetail UnitPrice="45.6000" Quantity="15">

          <Product Productname="Rössle Sauerkraut" UnitPrice="45.6000" />

        </OrderDetail>

        <OrderDetail UnitPrice="18.0000" Quantity="21">

          <Product Productname="Chartreuse verte" UnitPrice="18.0000" />

        </OrderDetail>

        <OrderDetail UnitPrice="12.0000" Quantity="2">

          <Product Productname="Spegesild" UnitPrice="12.0000" />

        </OrderDetail>

      </Order>

      <Order OrderID="10692" OrderDate="1997-10-03T00:00:00">

        <OrderDetail UnitPrice="43.9000" Quantity="20">

          <Product Productname="Vegie-spread" UnitPrice="43.9000" />

        </OrderDetail>

      </Order>

    </Customer>

     

    上面的XML非常自然的表现出客户、订单、订单细节、和产品之间的关系。这是因为在XML中,数据和元数据(Metadata)是结合在一起的。这个特点使XML具有自我解释的能力。这正是互联网数据传输所需耍的。

     

    SQL2000中,FORXML提供了非常简单快捷的方法将任何SELECT的结果变成任何的格式XMLOPENXML则可将任何的格式XML变成SELECT的结果。再加上SQLXMLAPISQL2000成为了第一个可直接面向互联网的关系性数据库。

     

    XML可以解决更多关系性数据库解决不了(or不好)的问题,特别是在数据模型(data modeling)方面:

    1. 半结构性semi-structure
    2. 分层hierarchical
    3. 保留顺序order preservation
    4. 非结构性un-structure

     

    通过下面的例子我们可以看到XML如何解决上述问题1,2,3.

     

    一个描述家族谱系的XML:

    <?xml version="1.0" encoding="utf-8"?>

    <成员 ="李一" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd">

     <成员 ="李二一" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd">

      <成员 ="李三一" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd">

      ...

      </成员>

       <成员 ="李三三" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd">

       ...

       </成员>

       <成员 ="李三四" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd">

        <成员 ="李四四" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd"/>

         <成员 ="李四六" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd">

          <成员 ="李五一" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd" ="李张氏">

           <成员 ="李六一" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd" ="李王氏">

            <成员 ="李七一" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd" ="李赵氏">

             <成员 ="李八一" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd" ="李张氏">

              <成员 ="李九一" 生日="yyyy-mm-dd" ="李胡氏" 职业="教师">

               <成员 ="李十一" 生日="yyyy-mm-dd" 职业="学生"/>

               </成员>

              </成员>

             </成员>

            </成员>

           </成员>

          </成员>

        <成员 ="李四七" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd"/>

        </成员>

       </成员>

     <成员 ="李二二" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd"/>

     <成员 ="李二三" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd">

      <成员 ="李三二" 生日="yyyy-mm-dd" 冥日="yyyy-mm-dd">

      ...

      </成员>

     </成员>

    </成员>

    从上面数据中,你可看出下述特点:

    1. 直观表现层次(hierarchical)。如要找出李五一所有直系子孙,只需执行查询 //成员[@="李五一"]
    2. 保留顺序(order preservation)。如要找出李第三个孩子的名字,只需执行查询 //成员[@="李二一"]/成员[3]/@
    3. 支持半结构性(semi-structure)数据。从李五一开始,增加了关于的新属性。从李九一开始,增加了关于职业的新属性。这些增加都不对已有数据产生影响。

    SQL2005通过对XML的内置(native support)和对XQuery的支持实现了上述功能.

  • [英文视频] 访谈吉姆·格雷: Sky Server 以及数据库技术的未来

    我想对数据库技术比较熟的朋友都应该听说过吉姆·格雷这个名字.  在我开始介绍有关SQL2005新的功能以前, 我想让大家看两段视频:

    http://channel9.msdn.com/ShowPost.aspx?PostID=49891

    http://channel9.msdn.com/Showpost.aspx?postid=50428

    在49891视频中吉姆谈了他们如何构建Sky Server (http://cas.sdss.org/dr4/en/): 一个把大部分宇宙空间数据存入SQL Server 并让你查询的网站.

    在50428视频中吉姆谈了他对未来数据库技术的一些看法.

     

  • 有关我TechEd讲座的补充资料(继续)

    我在讲座中用的demo.

    -- XML作为变量

    declare @x xml

    set @x = N'<根><元素 属性="1"/></根>'

    --select @x

    select @x.query(N'/根/元素')

    go

    -- XML作为列

    create table testXML (

    id int primary key,

    xmlcol xml )

    go

    -- 从XML文件中输入XML

    insert testXML select 1, *

    from Openrowset(bulk 'c:\JINGHAO\myXML.xml', single_blob) as x

    go

    -- 找出所有叫John的人

    select * from testXML

    select xmlcol.query('//person[@name="John"]')

    from testXML

    go

    -- 建立XML主索引

    create primary xml index p_xml_idx

    on testXML(xmlcol)

    go

    -- 建立索引后,查看查询计划的变化

    select xmlcol.query('//person[@name="John"]')

    from testXML

    go

    use adventureworks

    go

    -- query() 和 exist() 方法

    SELECT CatalogDescription.query(N'

    declare namespace PD="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";

    <Product 产品="{ /PD:ProductDescription[1]/@ProductModelID }" />

    ') as Result

    FROM Production.ProductModel

    where CatalogDescription.exist('

    declare namespace PD="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";

    declare namespace wm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain";

    /PD:ProductDescription/PD:Features/wm:Warranty ') = 1

    go

    -- value() 和 exist() 方法

    SELECT CatalogDescription.value('

    declare namespace PD="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";

    (/PD:ProductDescription/@ProductModelID)[1] ', 'int') as Result

    FROM Production.ProductModel

    WHERE CatalogDescription.exist('

    declare namespace PD="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";

    declare namespace wm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain";

    /PD:ProductDescription/PD:Features/wm:Warranty ') = 1

    go

    -- 一个典型的 XQuery

    select xmlcol.query('

    declare ns1 = "http://abc" ns2="xyz"

    for $p1 in //ns1:person, $p2 in //ns2:person[@name = "a"

    where //person[@spouse = $p/@name]

    order by $p/@name descending

    return

    <person name="{$p/@name}" job="{$p/@job}">

    <spouse name="{//person[@spouse=$p/@name]/@name}"

    job="{//person[@spouse=$p/@name]/@job}"/>

    </person>

    ')

    from testXML

    go

    -- XML_DML insert

    update testXML

    set xmlcol.modify('insert <dummy/> into /census[1]')

    go

    select xmlcol from testXML

    -- XML_DML delete

    update testXML

    set xmlcol.modify('delete /census/dummy')

    go

    -- XML_DML update value with

    update testXML

    set xmlcol.modify(N'replace value of (/census/person[@name="Bill"])[1]/@job

    with "Teacher"')

    go

    -- 建立XML架构集合

    create xml schema collection demoXSD as

    N'<schema xmlns="http://www.w3.org/2001/XMLSchema"

    targetNamespace="version1"

    xmlns:ns="version1">

    <element name="person" type="ns:personType" />

    <complexType name="personType">

    <sequence>

    <element name="姓名" type="string"/>

    <element name="性别" type="string"/>

    <element name="年龄" type="integer"/>

    </sequence>

    </complexType>

    </schema>'

    go

    -- 用被类型化的XML列(typed XML column)建表

    create table person(

    id int primary key,

    person xml(demoXSD)

    )

    go

    -- 插入符合架构version1的XML

    insert person values(1,

    N'<ns:person xmlns:ns="version1">

    <姓名>张三</姓名>

    <性别>男</性别>

    <年龄>23</年龄>

    </ns:person>')

    go

    -- XML架构进化

    alter xml schema collection demoXSD add

    '<schema xmlns="http://www.w3.org/2001/XMLSchema"

    targetNamespace="version2"

    xmlns:ns="version2">

    <element name="person" type="ns:personType" />

    <complexType name="personType">

    <sequence>

    <element name="姓名" type="string"/>

    <element name="性别" type="string"/>

    <element name="年龄" type="integer"/>

    <element name="教育" type="string"/>

    </sequence>

    </complexType>

    </schema>'

    go

    -- 插入符合架构version2的XML

    insert person values(2,

    N'<ns:person xmlns:ns="version2">

    <姓名>张三</姓名>

    <性别>男</性别>

    <年龄>23</年龄>

    <教育>大学</教育>

    </ns:person>')

    go

    -- 找出满足version1架构的人

    select person.query('declare namespace ns="version1"; //ns:person')

    from person

    where person.exist('declare namespace ns="version1"; //ns:person')= 1

    go

    -- FOR XML AUTO且将结果插入表中

    declare @x xml

    set @x = ( select * from production.product

    for xml auto, type )

    select @x.query('/*[contains(@Name, "Decal")]')

    insert into tableWithXML( xmlcol ) values( @x )

    go

    -- FOR XML PATH 可对元素和属性进行任意命名

    select top 10

    ProductID as [产品/@编号],

    Name as [产品/@名字],

    Color as [产品/@颜色],

    Size as [产品/特性/@尺寸],

    ListPrice as [产品/价格]

    from production.product

    where Color is not null

    and Size is not null

    for xml path, type

    go

    -- nodes() 方法让你把XML还原成SQL的行和列

    select ref.value('@name', 'varchar(20)') p1,

    ref.value('../@name', 'varchar(20)') p2

    from testXML cross apply xmlcol.nodes('//person') as T(ref)

    go

     

  • 有关我TechEd讲座的补充资料

    我在讲座之前,给大家了一个联结(link). 现在此再公布一下.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/sql2k5xml.asp

    这是一篇全面介绍SQL2005XML的文章. 内容非常详细.  它包括:

    • 动机(Motivating Scenarios for XML Storage),
    • 为什么用关系性来处理XML(Why Use Relational Databases for XML Data?),
    • XML数据类型 (XML data type),
    • 如何查询和删改(XML data type query and data modification),
    • 如何建索引(Indexing XML Data),
    • 演示程序(Example: in-proc access to the XML data type),
    • 如何利用XML进行数据建模(Data modeling considerations)

    等. 

    希望大家去读一下这篇文章.

     

  • My first blog post!

    To: 中国的SQL Server用户,

    今年是我第三次参加微软中国技术教育大会(MS China TechEd 2005). 每一次我都发现苦于时间太短,我   

    1. 无法讲完所有我想讲的内容
    2. 无法回答所有听众的问题
    3. 无法很好解释需要用数据和程序来说明的问题
    4. 无法让所有听众分享对某个好问题的回答

    当公司建议我们开设自己的博客,从而增加我们和用户之间的交流时,我突然发现了解决这些问题的方法:

       开一个专门有关SQL Server的中文博客.

    从1994年第一次上alt.chinese.text以来我在互联网上就只潜水,不上浮,最大的原因就是对输入中文的不自信. 不过这次我打算试试[:)]

    先登一下我的简历:
    刘劲浩: 1992就读于Stevens Institute of Technology, New Jersey并获计算机硕士学位. 1993年至1996年, 作为软件开发工程师就职于Princeton Softech. 参与设计和开发Relational Tools, 一个可以运行在DB2, Oracle, Sybase, XDB等数据库平台上的关系性数据管理工具. 96至1997,作为独立IT顾问商就职于Prudential Insurance. 参与设计和开发基于Oracle 数据库平台的中间件. 1997至今就职于微软SQL Server事业部. 参与设计和测试SQL Server查询处理器, SQLXML和XML Database等功能.

    我将陆续写或翻译一些介绍SQL Server 2005新功能的文章. 当然是从我最熟悉的XML功能讲起. 也欢迎大家给我提要求,告诉我你最想知道什么.

    希望大家"顶"我[:)]


© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker