Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

Generate A List Of Object Types By Using OBJECTPROPERTY

From Wiki

Jump to: navigation, search

How do you query the sysobjects system table and get the object type back for every single object You can use the type and xtype columns, these contain the following data

xtype
Object type. Can be one of these object types:
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
L = Log
FN = Scalar function
IF = Inlined table-function
P = Stored procedure
PK = PRIMARY KEY constraint (type is K)
RF = Replication filter stored procedure
S = System table
TF = Table function
TR = Trigger
U = User table
UQ = UNIQUE constraint (type is K)
V = View
X = Extended stored procedure


type
Object type. Can be one of these values:
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
FN = Scalar function
IF = Inlined table-function
K = PRIMARY KEY or UNIQUE constraint
L = Log
P = Stored procedure
R = Rule
RF = Replication filter stored procedure
S = System table
TF = Table function
TR = Trigger
U = User table
V = View
X = Extended stored procedure

Or you can use OBJECTPROPERTY. OBJECTPROPERTY is better in my opinion because you can see right away what you are looking for For example OBJECTPROPERTY ( id , 'IsUserTable' ) is much easier to understand than type = 'u'

Bu using CASE with OBJECTPROPERTY we can generate a nice report

  1. SELECT name,CASE
  2. WHEN OBJECTPROPERTY ( id , 'IsSystemTable' ) =1 THEN 'System Table'
  3. WHEN OBJECTPROPERTY ( id , 'IsProcedure' ) =1 THEN 'Procedure'
  4. WHEN OBJECTPROPERTY ( id , 'IsPrimaryKey' ) =1 THEN 'Primary Key'
  5. WHEN OBJECTPROPERTY ( id , 'IsDefault' ) =1 THEN 'Default'
  6. WHEN OBJECTPROPERTY ( id , 'IsForeignKey' ) =1 THEN 'Foreign Key'
  7. WHEN OBJECTPROPERTY ( id , 'IsCheckCnst' ) =1 THEN 'Check Constraint'
  8. WHEN OBJECTPROPERTY ( id , 'IsView' ) =1 THEN 'View'
  9. WHEN OBJECTPROPERTY ( id , 'IsConstraint' ) =1 THEN 'Constraint'
  10. WHEN OBJECTPROPERTY ( id , 'IsTrigger' ) =1 THEN 'Trigger'
  11. WHEN OBJECTPROPERTY ( id , 'IsScalarFunction' ) =1 THEN 'Scalar Function'
  12. WHEN OBJECTPROPERTY ( id , 'IsTableFunction' ) =1 THEN 'Table Valued Function'
  13. WHEN OBJECTPROPERTY ( id , 'IsRule' ) =1 THEN 'Rule'
  14. WHEN OBJECTPROPERTY ( id , 'IsExtendedProc' ) =1 THEN 'Extended Stored Procedure'
  15. WHEN OBJECTPROPERTY ( id , 'IsUserTable' ) =1 THEN 'User Table'
  16. END ObjectType, *
  17. FROM sysobjects


And of course there are a bunch of INFORMATION_SCHEMA views that you can use to get some of the same information back

  1. SELECT * FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS
  2. SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE
  3. SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
  4. SELECT * FROM INFORMATION_SCHEMA.TABLES
  5. SELECT * FROM INFORMATION_SCHEMA.VIEWS
  6. SELECT * FROM INFORMATION_SCHEMA.COLUMNS



Contributed by: --SQLDenis 16:38, 6 June 2008 (GMT)


Part of SQL Server Admin Hacks

342 Rating: 1.0/5 (3 votes cast)