一.OBJECT_ID
返回数据库对象标识号。
语法
OBJECT_ID ( 'object' )
例如:USE master
SELECT OBJECT_ID('pubs..authors')
查看pubs数据库里的authors表的object_id。
二.OBJECTPROPERTY
返回当前数据库中对象的有关信息。
语法
OBJECTPROPERTY ( id , property )
例如:OBJECTPROPERTY ( object_id('authors'),'ISTABLE') = 1
判断authors对象是否是一个表。
在查询器里输入:
use dye
select objectproperty(object_id('dbo.arranging'),'IsUserTable')
--------------------------
结果:(所影响的行数为 1 行)
========================================================================================
1.object_id(N'表名')
请问:if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PerPersonData]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
中的object_id(N'[dbo].[PerPersonData]')是什么意思?那个object_id函数?那个N?
还有OBJECTPROPERTY(id, N'IsUserTable') = 1中的OBJECTPROPERTY函数是什么意思?那个=1又是什么意思?
OBJECT_ID:返回数据库对象标识号。N是显式的将非unicode字符转成unicode字符,它来自 SQL-92 标准中的 National(Unicode)数据类型,用于扩展和标准化,在这里可以不用,写作object_id(PerPersonData)。
OBJECTPROPERTY:返回当前数据库中对象的有关信息。1表“真”。同样可以写成OBJECTPROPERTY(id, sUserTable) = 1。
整条语句的意思是判断数据库里有没有存在PerPersonData这样一张表。
=====================================================================
2.SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[#TEMPID1]') AND type in (N'U')
sys.objects ,OBJECT_ID(N'[dbo].[#TEMPID1]'); type in (N'U');各部分什么意思?谁能解释下?
答案:sys.ojects是一张表名
oject_id是取对象的ID
N表示使用Union Code,防止乱码。
==================================================================================
3. OBJECT_ID ('student', 'U')是什么意思 在SQL里
IF OBJECT_ID ('student', 'U') IS NOT NULL U 是什么意思
OBJECT_ID ( '[ database_name . [ schema_name ] . | schema_name . ]
object_name' [ ,'object_type' ] )
Object type:
AF = Aggregate function (CLR)
C = CHECK constraint
D = DEFAULT (constraint or stand-alone)
F = FOREIGN KEY constraint
FN = SQL scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued function
IF = SQL inline table-valued function
IT = Internal table
P = SQL Stored Procedure
PC = Assembly (CLR) stored-procedure
PG = Plan guide
PK = PRIMARY KEY constraint
R = Rule (old-style, stand-alone)
RF = Replication-filter-procedure
S = System base table
SN = Synonym
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
U = Table (user-defined)
UQ = UNIQUE constraint
V = View
X = Extended stored procedure