商讯信箱
用户名: @
密  码:   注册|忘记密码
登录
个人用户经销商
您的位置:首页 > 技术频道 > 正文

SQL Server 2008新版CTP特性解读

作者:Denny Cherry  2007-08-19

   对于HierarchyID数据类型,系统中有一些系统函数和方法与之相联系。有一些像GetLevel(),ParentChildOrg(),DescendantLimit()和GetAncestor()。下面显示了一个简单的经理和雇员之间的父子关系的例子。

  CREATE TABLE Organization
  (
  NodeLevel hierarchyid,
  EmployeeID int,
  OrgLevel as NodeLevel.GetLevel(),
  EmployeeName nvarchar(50) NOT NULL
  ) ;
  GO
  insert into Organization
  (NodeLevel, EmployeeID, EmployeeName)
  values
  (hierarchyid::GetRoot(),0, 'Bob')
  go
  Declare @Manager hierarchyid
  SELECT @Manager = hierarchyid::GetRoot()
  FROM Organization ;
  insert into Organization
  (NodeLevel, EmployeeId, EmployeeName)
  values
  (@Manager.GetDescendant(null, null), 1, 'Joe')
  go
  Declare @Manager hierarchyid
  declare @NodeLevel hierarchyid
  select @NodeLevel = NodeLevel
  from Organization
  where EmployeeName = 'Joe'
  SELECT @Manager = max(NodeLevel)
  FROM Organization
  where NodeLevel.GetAncestor(1) = @NodeLevel
  insert into Organization
  (NodeLevel, EmployeeID, EmployeeName)
  values
  (@NodeLevel.GetDescendant(@Manager, null),2, 'Sarah')
  go
  select NodeLevel.ToString()as NodeLevel_String, *
  FROM Organization
  go
  drop table Organization
  go


  Select语句的输出就像下面一样:

  NodeLevel_StringNodeLevelEmployeeIDOrgLevelEmployeeName
  /0x00Bob
  /1/0x5811Joe
  /1/1/0x5AC022Sarah

表格变量增进

  当表格变量增进在SQL Server 2008的先前版本中发布的时候,他们又值得被提及了。SQL Server 2008现在支持表格变量作为存储过程的输入参数。这需要在表格变量声明和存储过程声明中使用一个用户自定义的数据类型。下面就是一个基本实现的例子:

   Create a user-defined data type with a single column.
   Develop a procedure with a table variable as an input parameter.
   Declare a table variable of the type of the user defined data type.
   Loading 10 records into the table variable and pass the table variable to the stored procedure.
  create type tt_example AS TABLE
  (spid int)
  go
  create procedure usp_example
  @spids tt_example READONLY
  AS
  SELECT *
  FROM @spids
  GO
  declare @spids tt_example
  insert into @spids
  select top 10 spid
  from sys.sysprocesses
  exec usp_example @spids=@spids


  变到TEXT, NTEXT 和 IMAGE数据类型

  TEXT, NTEXT 和IMAGE数据类型有一些潜在的变化。在SQL Server 2008中,当数据被写到一个TEXT, NTEXT或者 IMAGE数据类型当中时,如果数据比8000字节少时(对于NTEXT来说是4000字符,对于TEXT和 IMAGE是8000)数据会被存储在行中,如果数据长度比上面提到的限制大的话,数据就被存储在一个单独的数据页中,这很像Microsoft SQL Server 2005和之前的版本对于数据存储的方式。当数据比那些限制大的时候,就需要一个数据指针,这也和先前的版本一样。

  在SQL Server 2008 July CTP和T-SQL数据类型中有很多新的和另人兴奋的变化。尽管还有更加新的和改进的特性会在将来的版本中发布。


1 2
【内容导航】
第1页: SQL Server 2008 CTP安装 第2页: 表格变量增进
©版权所有。未经许可,不得转载。
[责任编辑:晓熊]
[an error occurred while processing this directive]