Labels

Friday, January 9, 2009

08 - Database Objects (DDL)

Hi,

 

Here we'll cover below –

 

-          Table

-          Constraints

-          View

-          SP

-          Functions

-          Index

-          Triggers

 

 

Database Objects

 

 

sp_rename

 

-                                To rename a database object

-                                Use this procedure with caution, as changing object names can break references to the object referenced in triggers, stored procedures, views, or anything else that may be expecting the original name.

 

sp_rename @objname = <'object_name'>,

@newname = <'new_name'>,

@objtype = <'object_type'>

 

 

EXEC sp_rename 'trg_BookAudit', 'trg_BookAudit_INSERT'

EXEC sp_rename 'Authors.vchIndicator', 'vchIndicator', 'column'

 

 

sp_help

 

-                                Returns helpful information about a database object

 

EXEC sp_help 'Books

 

sp_depends

 

-                                When you create objects such as foreign key constraints, views, stored procedures, and triggers, you create dependencies on other database objects.

-                                Dependencies cause problems if you change the referenced objects without changing the object doing the referencing.

-                                Use the sp_depends system stored procedure to reveal dependencies for an object.

 

 

EXEC sp_depends 'Books'

 

 

sp_changeobjectowner

 

EXEC sp_changeobjectowner 'JackSmith.Books', 'dbo'

 

 

OBJECTPROPERTY

 

-                                Allows you to query meta data properties of your database objects.

 

SELECT OBJECTPROPERTY (object_id , property_name)

 

SELECT OBJECTPROPERTY (OBJECT_ID('Books'), 'HasInsertTrigger')

 

 

 

 

 

Hope this helps.

 

Thanks & Regards,

Arun Manglick || Tech Lead

No comments:

Post a Comment