May 2, 2013 at 11:49 pm
I have a table with following column.(I have directly give the create table command)
CREATE TABLE [dbo].[BalanceTable](
[AccountID] [int] NOT NULL,
[Type] [varchar](10) NULL,
[Date] [date] NOT NULL,
[Balance] [decimal](15, 2) NULL,
[TRansactionDr] [decimal](15, 2) NULL,
[TRansactionCr] [decimal](15, 2) NULL,
[daily_Balance] [xml] NULL,
CONSTRAINT [PK_BalanceTable] PRIMARY KEY CLUSTERED
(
[AccountID] ASC,
[Date] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
I have a xml query which updates this table. But it works slowly and take some seconds. I want to speed it up. So i was try to use xml index.So in this case which index i should use? Primary? secondary(in that i have path,value and property)? So which will be better to use which will reduce time required for execution.
Below is query
Update BalanceTable set [daily_balance].modify('replace value of (/Root/Row[date=''2011-03-23'']/Balance/text())[1] with (/Root/Row[date=''2011-03-23'']/ Balance)[1] +1') where [AccountID]=26 and [Date]='31-Mar-2011' and [daily_balance].exist('/Root/Row[date=''2011-03-23'']')=1;
Also here is sample of xml column
<Root>
<Row>
<Rowid>0</Rowid>
<date>2011-01-23</date>
<Balance>0.0E0</Balance>
<TRansactionDr>0.0E0</TRansactionDr>
<TRansactionCr>0.0E0</TRansactionCr>
</Row>
<Maxrowid>0</Maxrowid>
<Row>
<Rowid>0</Rowid>
<date>2011-01-31</date>
<Balance>123</Balance>
<TRansactionDr>123</TRansactionDr>
<TRansactionCr>0.0E0</TRansactionCr>
</Row>
</Root>
So please give me suggestions
May 3, 2013 at 2:58 am
Hi,
Because you use exist() you should create FOR PATH type xml index.
Regards
IgorMi
Igor Micev,My blog: www.igormicev.com
May 3, 2013 at 3:15 am
Ok. But while creating PATH type index is there needed to specify the path which i use?
I don't know much about xml indexing. But for other datatypes there is option of filtered index where i can specify the condition.
So is there any option in xml also? If not then for which path it will create index for xml column?
May 3, 2013 at 3:36 am
IT researcher (5/3/2013)
Ok. But while creating PATH type index is there needed to specify the path which i use?I don't know much about xml indexing. But for other datatypes there is option of filtered index where i can specify the condition.
So is there any option in xml also? If not then for which path it will create index for xml column?
No, you don't need to specify any paths
Can you try this?
create primary xml index PXML_daily_Balance on BalanceTable(daily_Balance)
create xml index [SECXMl_daily_Balance_path] on BalanceTable(daily_Balance)
using xml index [PXML_daily_Balance] for path
Regards,
IgorMi
Igor Micev,My blog: www.igormicev.com
May 3, 2013 at 5:48 am
Whether i can use selective xml index? Does it available in sql server 2008 r2 express?
May 3, 2013 at 6:43 am
IT researcher (5/3/2013)
Whether i can use selective xml index? Does it available in sql server 2008 r2 express?
It's available from sql server 2012.
Igor Micev,My blog: www.igormicev.com
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply