473,781 Members | 2,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update clustered column in place?

Is there any way to update a column in a clustered index without incurring
the cost of reordering.

Example:
Create table TableX (
Col1 int,
Col2 smalldatetime,
Col3 varchar(10))
go
create clustered indext ix_test on tableX (Col2, Col1)
go
update TableX set Col2 = '2004-12-07'

-- Yes I specifically left off the criteria to update every row.

It would seem to me in this situation that the data types require the same
storage, all rows are being updated in one transaction, and there's no new
to reorder since all will be the same.

Thanks,
Danny
Jul 23 '05 #1
2 1524
Danny,

No, when a key column in an index is updated, the row has to be deleted and
re-inserted into the index, even if all rows in the index are updated to the
same value. Server has to keep the index(btree) consistent without any out
of order row at any point of time for many reasons. For example, this is
needed to for concurrent user of the index to read the index while the
update is being performed. Even if the user ask to do the update under a
table lock, it is needed to make concurrent user conducting nolock scan
work, and most importantly if the update transaction rollback in the middle
or the server crashes in the middle of the update, undo of the update
transaction requires the btree to be consistent at any point of time.

--
Gang He
Software Design Engineer
Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.
"Danny" <is****@flash.n et> wrote in message
news:V6******** ***********@new ssvr33.news.pro digy.com...
Is there any way to update a column in a clustered index without incurring
the cost of reordering.

Example:
Create table TableX (
Col1 int,
Col2 smalldatetime,
Col3 varchar(10))
go
create clustered indext ix_test on tableX (Col2, Col1)
go
update TableX set Col2 = '2004-12-07'

-- Yes I specifically left off the criteria to update every row.

It would seem to me in this situation that the data types require the same
storage, all rows are being updated in one transaction, and there's no new
to reorder since all will be the same.

Thanks,
Danny

Jul 23 '05 #2
Danny (is****@flash.n et) writes:
Is there any way to update a column in a clustered index without incurring
the cost of reordering.

Example:
Create table TableX (
Col1 int,
Col2 smalldatetime,
Col3 varchar(10))
go
create clustered indext ix_test on tableX (Col2, Col1)
go
update TableX set Col2 = '2004-12-07'

-- Yes I specifically left off the criteria to update every row.

It would seem to me in this situation that the data types require the same
storage, all rows are being updated in one transaction, and there's no new
to reorder since all will be the same.


Maybe if you had updated Col1. But now you are updating the lead column:

INSERT TableX (Col1, Col2, Col3)
VALUES (1, '20040101', 'Slabank')
INSERT TableX (Col1, Col2, Col3)
VALUES (2, '20030101', 'Slabank')

When you perform the update above, the two rows will have to change places.

In practice, even if you updated Col1, I would not be surprised if there
were data moved around. Recall that in a non-unique clustered index,
SQL Server adds a four-byte uniquifier, and your update could force a
change in these. And this could lead to data being moved, although I
can't really say that I know that this will happen.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3845
by: M Wells | last post by:
Hi All, I have a database that is serving a web site with reasonably high traffiic. We're getting errors at certain points where processes are being locked. In particular, one of our people has suggested that an update statement contained within a stored procedure that uses a where condition that only touches on a column that has a clustered primary index on it will still cause a table lock.
10
2212
by: R Camarda | last post by:
I have the following statement that takes quite a long time. Longest of any of my SQL statment updates. UPDATE F_REGISTRATION_STD_SESSION SET PREVIOUS_YEAR_SESSION_ID = ( SELECT s.previous_year_session_id FROM F_REGISTRATION_STD_SESSION R ,DS_V4_TARGET.dbo.D_H_Session_By_SessQtr S WHERE r.STUDENT_ID = F_REGISTRATION_STD_SESSION.STUDENT_ID
4
3847
by: Tryfon Gavriel | last post by:
Hi all I recently noticed when trying to optimise a major query of a chess website I am the webmaster of, that adding an order by for "gamenumber" which is a clustered index field as in for example "order by timeleft desc, gamenumber desc" actually speeded up the queries and reduced sql server 2000 timeouts. I have an ASP error log and I am fairly sure that a dramatic reduction in sql server timeouts is simply attributed to adding an...
2
2354
by: Miss Livvy | last post by:
Would it be OK to use varchar(5) instead of char(5) as the first field of a composite clustered index? My gut tells me that varchar would be a bad idea, but I am not finding much information on this topic on this when I Google it. Currently the field is Char(4), and there is a need to increase it to hold 5 characters. TIA
4
5808
by: Thomas R. Hummel | last post by:
Hello, I am writing a stored procedure that will take data from several different tables and will combine the data into a single table for our data warehouse. It is mostly pretty straightforward stuff, but there is one issue that I am not sure how to handle. The resulting table has a column that is an ugly concatenation from several columns in the source. I didn't design this and I can't hunt down and kill the person who did, so that...
16
3877
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the table, or perhaps bytes, being updated where the engine just decides, screw it, i'll just make a new one. surfed this group and google, but couldn't find anything. the context: we have some java folk who like to parametize/
5
9724
by: pb648174 | last post by:
I've been doing a bit of reading and have read in quite a few places that an identity column is a good clustered index and that all or at least most tables should have a clustered index. The tool I used to generate tables made them all with non clustered indexes so I would like to drop all of them and generate clustered indexes. So my questions is a) good idea? and b) how? There are foreign key references to most of them so those would...
22
5439
by: pbd22 | last post by:
hi. I am having probelms with an update statement. every time i run it, "every" row updates, not just the one(s) intended. so, here is what i have. i have tried this with both AND and OR and neither seem to work. i dont know why this is elluding me, but i'd appreciate help with the solution.
4
7254
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which - "Modified" of type DateTime - is hidden since it should not be edited by a user. The system handles the update for this column. So, I have hidden (Visible=false) this column on the grid. In order to access the value in this field, I have created a...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.