SQL Server 2008一个酷酷的函数:fn_PhysLocFormatter,返回记录的rowid

来源:这里教程网 时间:2026-03-02 10:00:40 作者:

1> create table t(a int identity, b char(5) default 'x')
2> go
1> insert into t default values
2> go 5

1> select sys.fn_PhysLocFormatter(%%physloc%%) as RID, * from t
2> go
RID a b
---------- ----------- -----
(1:21:0) 1 x
(1:21:1) 2 x
(1:21:2) 3 x
(1:21:3) 4 x
(1:21:4) 5 x

与Oracle的DBMS_ROWID包中的函数功能相同,但是这个更好用。

另外一个函数是sys.fn_physLocCracker ,其用法如下:

1> create table t(a int)
2> insert into t values(1)
3> insert into t values(2)
4> insert into t values(3)
5> insert into t values(4)
6> go

1> select * from t Cross Apply sys.fn_physLocCracker (%%physloc%%) AS plc;
2> go
a file_id page_id slot_id
----------- ----------- ----------- -----------
1 1 278 0
2 1 278 1
3 1 278 2
4 1 278 3

[@more@]

相关推荐