Showing posts with label primary. Show all posts
Showing posts with label primary. Show all posts

Wednesday, March 28, 2012

Padding an auto-incremented Int column to ten zeros

Good day gentleman,
Is it possible to pad columns of Int data type with zeros?

I currently have a primary key column of data type Int which is auto-incremented by 1. My problem is I need to pad the auto-incremented ID's with ten zeros so, 0000000009 instead of 9.

I can pad the ID's in the c# dataaccess layer, but i need to generate/store them padded in the database to allow direct reporting.

I am using Enterprise Manager and i can see a Formula field when the table is in design view, can i use this? i am just guessing here.

Any comments or pointers would be a big help.What you are discussing is a display issue. An int is, by definition, isolated from any particular display formatting. It is just a number. You could add an additional column (nvarchar) and have a trigger on inserts that populates that nvarchar() column with a string value with 0 padding.

PAD_INDEX : activating or not ?

Hi all,

On SQL Server 7 SP4.

3 tables with about 100 000 rows each one, frequently updated.
1 clustered index on primary key, and 2 non clustered index on columns used by JOIN and by queries.

Fillfactor for index : 90.
PAD_INDEX : not activated.

I have some deadlocks problems, probably due to index pages and key locking (as precised in error log). Is it possible that the cause of that is splitting index pages while UPDATE ?

May I activate PAD_INDEX to solve part of this problem ?

Thanks for any helpIt's a performance issue thing, I don't think that's your problem

http://www.sql-server-performance.com/oltp_performance.asp|||Well, the nature of deadlocks has NOTHING to do with performance, thus cannot be fixed by recommendations given in the link. The only applicable advice which is not even in the section implied is to keep your transactions short. This will minimize the possibility of deadlocks, but will not eliminate them. As you all know, it deals with object access order, and should be addressed accordingly, by examining all possible transactions involving the same set of objects in reverse order.|||Thanks all, I'm going to have a look at it.|||pad index is really not neccesary. i have chased this guy down many roads
i even had extended conversations with kimberly tripp and kalen delaney on this and everyone i have talked to has told me that pad index is just not gonna provide any real advantage.

Wednesday, March 7, 2012

Overwriting entry in table

Task:

To insert entries into a table. The table has a primary key based on a field 'ID'. When inserting into the destination table, I want to make sure that the new entry will overwrite the old entry.

What's the quickest/cleaniest way to do this ?

thanks,
ClaytonUPDATE <table>
SET <column>=<value>, etc...
WHERE field_id = <field_id>