Search This Blog

Thursday, August 9, 2007

Sysobjects

Interesting Table Design of sysobjects
Sysobjects is the meta data table which gets populated whenever objects like Tables,Views,Procs,Functions,Primary Keys are created.

If you look at table definition then you may find unique clustered index located on id column.
And also in relationships only the ID column is used in various tables like syscolumns,syscomments,etc..

So what it means from the table structure is there can be more than object with same name as there is no uniqueness enforced on name as such by table design.Now lets try these steps.

Create table T1
( A Int)
Go

You receive a message "Commands completed successfully"

Now we create one more object with same T1 as
create proc t1
as
begin
set nocount on
end

On executing the same i receive a error message as

Msg 2714, Level 16, State 3, Procedure t1, Line 5
There is already an object named 't1' in the database.

So we get to know that this validation is enforced at SQL application level that name is again a unique key so that the same objects names cannot exist in two different object types.

No comments: