Friday, February 24, 2012

Logic Behind Object_ID

I have 2 basic requirements as below,

1) Comparing 2 versions of same database.

2) Keeping track of schema versions of Tables & Stored Procedures so that I can rollback to previous schema.

I have started with Sys.Objects, Sys.Tables & Sys.Columns and I kept things rely on Object_ID but the problem started whenever I change some part of Table. It assigns new Object_ID to the table whenever I change it; moreover creationdate of object is also changed. So I assume that it drops and creates new table.

Please throw some light on following questions,

1) When and How Object_ID Changes?

2) Is there any other thing in database which is Unique & Not Changing with alteration of object?

3) What should be the preferred way to Compare 2 Database?

I hate readymade tools as they charge per user and my requirements are very small.

Thanking you,

Object_ID is internal, and can definitely change when you call the ALTER TABLE / ALTER INDEX statements when the engine decides it is easier to create a new object than to modify the existing table.

The best way to keep track of different version of tables and stored procedures is to use a source control system (like VSTS/SourceSafe). Each time you load a new version in the database, you store the database script in the source control system. If you need to get back to an old version, you simply get the version from source control.

To compore 2 versions of the same database, you can use VSTS for database professionals, which contains this functionality.

Thanks,|||

Versioning is OK. We can easily maintain with Source Control

But Real Headache is DataBase Comparsion, We cannot afford to go for VSTS so there should be some other alternative.

Can you give a brick (clue) for object_id or anything else using which I can build building?

Thanks

|||Would it be possible to use the table name to compare, or do you need to do compares of tables with different names?

Thanks,|||I would definitely use objectname instead of id. Since it's not possible to have to objects with the same name for the same schema. You're guarantee to find the object you're looking for to compare.

No comments:

Post a Comment