Saturday, February 25, 2012

A quicker way of performing this XML query?

Hi all

I have the following query that makes up part of a table-value-function i've written in SQL 2K5.

XML Query


SELECT CONVERT(XML, objectdata).value('(/xmlData/IsTrue)[1]', 'bit') as IsTrue
from myTable
where idfield = [@.FunctionTable].ID


Until adding this query, the function ran in under 60 seconds. Adding this query has added an extra 120 seconds to the function execution time.


This query is called around 200 times in the function as part of an update:

UPDATE @.FunctionTable set ...

....

, FieldValue = (SELECT CONVERT(XML, objectdata).value('(/xmlData/IsTrue)[1]', 'bit') as IsTrue
from myTable
where idfield = [@.FunctionTable].ID)

Is there a more performant way to do the same XML lookup?

Many Thanks

Are there any XML indexes created?

WesleyB

Visit my SQL Server weblog @. http://dis4ea.blogspot.com

|||Probabaly not, would this index be placed upon the source field?
|||

You can create an index on the field where you do the XQuery.

WesleyB

Visit my SQL Server weblog @. http://dis4ea.blogspot.com

A quicker way of performing this XML query?

Hi all

I have the following query that makes up part of a table-value-function i've written in SQL 2K5.

XML Query


SELECT CONVERT(XML, objectdata).value('(/xmlData/IsTrue)[1]', 'bit') as IsTrue
from myTable
where idfield = [@.FunctionTable].ID


Until adding this query, the function ran in under 60 seconds. Adding this query has added an extra 120 seconds to the function execution time.


This query is called around 200 times in the function as part of an update:

UPDATE @.FunctionTable set ...

....

, FieldValue = (SELECT CONVERT(XML, objectdata).value('(/xmlData/IsTrue)[1]', 'bit') as IsTrue
from myTable
where idfield = [@.FunctionTable].ID)

Is there a more performant way to do the same XML lookup?

Many Thanks

Are there any XML indexes created?

WesleyB

Visit my SQL Server weblog @. http://dis4ea.blogspot.com

|||Probabaly not, would this index be placed upon the source field?
|||

You can create an index on the field where you do the XQuery.

WesleyB

Visit my SQL Server weblog @. http://dis4ea.blogspot.com

a quick question about subscription

when I create a subscription through report manager it work ,but if I create
the subscription through my application (I'm using my own domain credentials
to authenticate to the server).It dosen't work.
Any idea?
ThanksHow does it fail? Does the create fail or the subscription fail when it
runs?
--
-Daniel
This posting is provided "AS IS" with no warranties, and confers no rights.
"J-R" <RayAll@.microsft.com> wrote in message
news:uLFwfi1VFHA.2128@.TK2MSFTNGP15.phx.gbl...
> when I create a subscription through report manager it work ,but if I
> create the subscription through my application (I'm using my own domain
> credentials to authenticate to the server).It dosen't work.
> Any idea?
> Thanks
>|||No it create the subscription,but it necer run the subscrition.My ASP.NET
application is in different box than Reporting Services and they both using
NTLM.
Thanks
"Daniel Reib (MSFT)" <danreib@.online.microsoft.com> wrote in message
news:uAt65%232VFHA.1452@.TK2MSFTNGP14.phx.gbl...
> How does it fail? Does the create fail or the subscription fail when it
> runs?
> --
> -Daniel
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> "J-R" <RayAll@.microsft.com> wrote in message
> news:uLFwfi1VFHA.2128@.TK2MSFTNGP15.phx.gbl...
>> when I create a subscription through report manager it work ,but if I
>> create the subscription through my application (I'm using my own domain
>> credentials to authenticate to the server).It dosen't work.
>> Any idea?
>> Thanks
>|||Is there any status shown after the subscription fires? After you create
the subscription through your app, can you view it through Report Manager?
--
-Daniel
This posting is provided "AS IS" with no warranties, and confers no rights.
"J-R" <RayAll@.microsft.com> wrote in message
news:OtgYYP9VFHA.2960@.TK2MSFTNGP15.phx.gbl...
> No it create the subscription,but it necer run the subscrition.My ASP.NET
> application is in different box than Reporting Services and they both
> using NTLM.
> Thanks
> "Daniel Reib (MSFT)" <danreib@.online.microsoft.com> wrote in message
> news:uAt65%232VFHA.1452@.TK2MSFTNGP14.phx.gbl...
>> How does it fail? Does the create fail or the subscription fail when it
>> runs?
>> --
>> -Daniel
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> "J-R" <RayAll@.microsft.com> wrote in message
>> news:uLFwfi1VFHA.2128@.TK2MSFTNGP15.phx.gbl...
>> when I create a subscription through report manager it work ,but if I
>> create the subscription through my application (I'm using my own domain
>> credentials to authenticate to the server).It dosen't work.
>> Any idea?
>> Thanks
>>
>|||I think I solved the problem,it was the problem of the user account we
create the suscription uder.That guy did not have enough previlliage to
execute a subscription.
Thanks for your help
"Daniel Reib (MSFT)" <danreib@.online.microsoft.com> wrote in message
news:%230vs3rDWFHA.2124@.TK2MSFTNGP14.phx.gbl...
> Is there any status shown after the subscription fires? After you create
> the subscription through your app, can you view it through Report Manager?
> --
> -Daniel
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> "J-R" <RayAll@.microsft.com> wrote in message
> news:OtgYYP9VFHA.2960@.TK2MSFTNGP15.phx.gbl...
>> No it create the subscription,but it necer run the subscrition.My ASP.NET
>> application is in different box than Reporting Services and they both
>> using NTLM.
>> Thanks
>> "Daniel Reib (MSFT)" <danreib@.online.microsoft.com> wrote in message
>> news:uAt65%232VFHA.1452@.TK2MSFTNGP14.phx.gbl...
>> How does it fail? Does the create fail or the subscription fail when it
>> runs?
>> --
>> -Daniel
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> "J-R" <RayAll@.microsft.com> wrote in message
>> news:uLFwfi1VFHA.2128@.TK2MSFTNGP15.phx.gbl...
>> when I create a subscription through report manager it work ,but if I
>> create the subscription through my application (I'm using my own domain
>> credentials to authenticate to the server).It dosen't work.
>> Any idea?
>> Thanks
>>
>>
>

A quick question

I have an update statement, in which one of the columns I would only like to update if a condtion is true. How do i do this in my update statement? I am tring the following but doesnt seem to work. Is there a way to only update a column, if a condition(value in input parameter-sp) is true. Please let me know, I am eagerly waiting for some tips. This upd statement is inside a sproc.

UPDATE tblname SET

[NSLDSFlag] = @.NSLDSFlag,

[PinID] = @.PinID,

[PnoteSequenceNumber] = @.PnoteSequenceNumber,

IF (@.ApplicationStatus = 100) THEN [ProcessReturnCode] = NULL,

[ProofOfEmploy] = @.ProofOfEmploy,

[ProofOfEnroll] = @.ProofOfEnroll,

[ProofOfID] = @.ProofOfID

Try the example below.

Chris

UPDATE tblname SET

[NSLDSFlag] = @.NSLDSFlag,

[PinID] = @.PinID,

[PnoteSequenceNumber] = @.PnoteSequenceNumber,

[ProcessReturnCode] = CASE WHEN (@.ApplicationStatus = 100) THEN NULL ELSE [ProcessReturnCode] END,

[ProofOfEmploy] = @.ProofOfEmploy,

[ProofOfEnroll] = @.ProofOfEnroll,

[ProofOfID] = @.ProofOfID

|||It compiles fine, but when I try to run it, it doesnt set the ProcessReturnCode to NULL, if the condition is true. Any idea ?|||Is it not possible to do this using IF Condition, seems very easy, but apparently having a tough time figuring this out. Any help would be appreciated.|||

Try this variation on Chris' suggestion:

UPDATE tblname
SET
[NSLDSFlag] = @.NSLDSFlag,
[PinID] = @.PinID,
[PnoteSequenceNumber] = @.PnoteSequenceNumber,
[ProcessReturnCode] = CASE @.ApplicationStatus
WHEN 100 THEN NULL
ELSE [ProcessReturnCode]
END,
[ProofOfEmploy] = @.ProofOfEmploy,
[ProofOfEnroll] = @.ProofOfEnroll,
[ProofOfID] = @.ProofOfID

Of course, this would only reliably work if @.ApplicationStatus is an integer -and ProcessReturnCode allows NULL values.

|||

The test example below shows that the concept works absolutely fine - maybe there's a problem elsewhere in the code that you're working with?

Chris

DECLARE @.TestTable TABLE (ID INT, String VARCHAR(10) NULL)

INSERT INTO @.TestTable(ID, String)

SELECT 1, 'TestValue'

SELECT ID, String AS [OriginalValue]

FROM @.TestTable

--1 TestValue

DECLARE @.TestValue INT

SET @.TestValue = 0

UPDATE @.TestTable

SET String = CASE WHEN @.TestValue = 100 THEN NULL ELSE String END

SELECT ID, String AS [FailedCondition]

FROM @.TestTable

--1 TestValue

SET @.TestValue = 100

UPDATE @.TestTable

SET String = CASE WHEN @.TestValue = 100 THEN NULL ELSE String END

SELECT ID, String AS [PassedCondition]

FROM @.TestTable

--1 NULL

|||

You can't use IF in an UPDATE statement. The CASE example above should work fine and is well-suited to your application, however if you decide you want to use IF then you could use the code below.

Again, as Arnie pointed out, @.ApplicationStatus should be an INT datatype, and the ProcessReturnCode column must be able to accept NULLs.

Chris

IF @.ApplicationStatus = 100

UPDATE tblname SET

[NSLDSFlag] = @.NSLDSFlag,

[PinID] = @.PinID,

[PnoteSequenceNumber] = @.PnoteSequenceNumber,

[ProcessReturnCode] = NULL,

[ProofOfEmploy] = @.ProofOfEmploy,

[ProofOfEnroll] = @.ProofOfEnroll,

[ProofOfID] = @.ProofOfID

ELSE

UPDATE tblname SET

[NSLDSFlag] = @.NSLDSFlag,

[PinID] = @.PinID,

[PnoteSequenceNumber] = @.PnoteSequenceNumber,

[ProofOfEmploy] = @.ProofOfEmploy,

[ProofOfEnroll] = @.ProofOfEnroll,

[ProofOfID] = @.ProofOfID

A quick counting question

Once more I searched around but couldn't get a good handle on it.

The problem is this:

1) I send a notifier out to X no. of people
2) Y no. of people click on the notifier
3) I need to be able to get the percentage of Y/X

table structure tblNotifier:

OBJID
Recipient
Return_Status

I can do it with 2 queries, but I'd love to do it with 1

Select count(*) from tblNotifier;
Select count(*) from tblNotifier where return_status=1;

and then do the math in ASP, but... really, that's just not a whole lot of fun.

Thanks,
Robhow about : --

select sum (convert(numeric,Return_Status))/convert(numeric,count(recipient)) *100 from tblNotifier|||Originally posted by Enigma
how about : --

select sum (convert(numeric,Return_Status))/convert(numeric,count(recipient)) *100 from tblNotifier

'k How much does an explanation of why that works cost?

Thanks, Rob|||select
sum (convert(numeric,Return_Status)) -- Take the return status (1 for those who have replied , 0 for not replied) and sum it up
/ -- division
convert(numeric,count(recipient)) -- no of rows

*100 -- for percentage purposes

from tblNotifier -- Your table

;)|||I'm just an ass evidently.. 20 seconds of thought and I see why that works. All apologies

And thank you very much for pointing out my intellectual shortcomings :)

Rob|||Again ..
In case Return_Status is int ... you can simply say ...

select sum (Return_Status)/convert(numeric,count(recipient)) *100 from tblNotifier

though i assume it should be of type bit|||I'm just straight summing it becuase it is of type int. I was worried that they would add some random criteria for return_status, and have 3 or 4 different status options. So this way, it's not a big pain to add another table and reference it in.

But it works great, so thanks a bunch.

Rob

A questions about OS!

Can I use IIS on my WindowsXP Home Edition?
If it can ,then Where should I download the IIS5.0(if have the setup package in the world) and can I setup it on my XP Home Edition?

By the way ,I have try to install the XP Professional but I can't find the proper Drivers so I had to use the DEfault CDROM to install the XP Home Editon on my notebook.So now I want to use the HomeEditon,the question is ...Can I use IIS5.0?I debug my ASP web with DW.IF It can go.where should I download the IIS?Please show me the LINK..Thanks.
This is my first time to post the thread on this forum.Hope to make more friends...hehe~~~~~According to documentation - you can't run iis on xp home. But according to this article you can - I can't disclose whether or not it works but it seems that this has worked for almost a year :-)

article (http://www.15seconds.com/issue/020118.htm )|||My problem has been solved ,Thank U~~ ^_^

A question related to stored procedure

Suppose there is a database table which contains information of a
complete binary tree.
A complete binary tree is always populated depth wise. A certain level
is filled up completely before going further level
down.
The table contains sequential information of the tree. As shown in the
following, the table on the right contains the tree information on the
left after inserting 4 nodes.
ID Name tree
1 N0 N0
2 N1
N1 N2
3 N2
And after inserting 4 nodes the table becomes as below.
ID Name Tree
1 N0 N0
2 N1 N1 N2
3 N2 N3
4 N3
Given a table containing the node information (the number of nodes is
arbitrary) of a complete binary tree as above.
A stored procedure have to write to construct and print a table,
where
the names of the nodes will appear in different rows and
columns of
the table and
the total arrangement will appear like a binary tree of the
following figure.
N0
N1 N2
N3
N4 N5 N6
N7 N8
Hi
"babu" wrote:

> Suppose there is a database table which contains information of a
> complete binary tree.
> A complete binary tree is always populated depth wise. A certain level
> is filled up completely before going further level
> down.
> The table contains sequential information of the tree. As shown in the
> following, the table on the right contains the tree information on the
> left after inserting 4 nodes.
> ID Name tree
> 1 N0 N0
> 2 N1
> N1 N2
> 3 N2
> And after inserting 4 nodes the table becomes as below.
> ID Name Tree
> 1 N0 N0
> 2 N1 N1 N2
> 3 N2 N3
> 4 N3
> Given a table containing the node information (the number of nodes is
> arbitrary) of a complete binary tree as above.
> A stored procedure have to write to construct and print a table,
> where
> · the names of the nodes will appear in different rows and
> columns of
> the table and
> · the total arrangement will appear like a binary tree of the
> following figure.
> N0
> N1 N2
> N3
> N4 N5 N6
> N7 N8
>
Printing is a function for the client to deal with not SQL Server. How you
store and return the hierarchy/tree from SQL Server depends on the model you
are using e.g. nested set or adjacency. Joe Celko's Trees and Hierarchies
book ISBN 1-55860-920-2 (and there are plenty of posts on this!) will give
you some background on this. SQL Server 2005 has the ability for recursive
queries using CTEs which can be ustilised to traverse your hierarchy if you
are using this version.
John
|||I believe one or more of Itzik Ben-Gan's books cover trees/graphs as well.
Very good reads.
TheSQLGuru
President
Indicium Resources, Inc.
"babu" <nasif4003@.gmail.com> wrote in message
news:1179497643.034074.249710@.p77g2000hsh.googlegr oups.com...
Suppose there is a database table which contains information of a
complete binary tree.
A complete binary tree is always populated depth wise. A certain level
is filled up completely before going further level
down.
The table contains sequential information of the tree. As shown in the
following, the table on the right contains the tree information on the
left after inserting 4 nodes.
ID Name tree
1 N0 N0
2 N1
N1 N2
3 N2
And after inserting 4 nodes the table becomes as below.
ID Name Tree
1 N0 N0
2 N1 N1 N2
3 N2 N3
4 N3
Given a table containing the node information (the number of nodes is
arbitrary) of a complete binary tree as above.
A stored procedure have to write to construct and print a table,
where
the names of the nodes will appear in different rows and
columns of
the table and
the total arrangement will appear like a binary tree of the
following figure.
N0
N1 N2
N3
N4 N5 N6
N7 N8

A question related to stored procedure

Suppose there is a database table which contains information of a
complete binary tree.
A complete binary tree is always populated depth wise. A certain level
is filled up completely before going further level
down.
The table contains sequential information of the tree. As shown in the
following, the table on the right contains the tree information on the
left after inserting 4 nodes.
ID Name tree
1 N0 N0
2 N1
N1 N2
3 N2
And after inserting 4 nodes the table becomes as below.
ID Name Tree
1 N0 N0
2 N1 N1 N2
3 N2 N3
4 N3
Given a table containing the node information (the number of nodes is
arbitrary) of a complete binary tree as above.
A stored procedure have to write to construct and print a table,
where
=B7 the names of the nodes will appear in different rows and
columns of
the table and
=B7 the total arrangement will appear like a binary tree of the
following figure.
N0
=20
N1 N2
N3
N4 N5 N6
N7 N8Hi
"babu" wrote:

> Suppose there is a database table which contains information of a
> complete binary tree.
> A complete binary tree is always populated depth wise. A certain level
> is filled up completely before going further level
> down.
> The table contains sequential information of the tree. As shown in the
> following, the table on the right contains the tree information on the
> left after inserting 4 nodes.
> ID Name tree
> 1 N0 N0
> 2 N1
> N1 N2
> 3 N2
> And after inserting 4 nodes the table becomes as below.
> ID Name Tree
> 1 N0 N0
> 2 N1 N1 N2
> 3 N2 N3
> 4 N3
> Given a table containing the node information (the number of nodes is
> arbitrary) of a complete binary tree as above.
> A stored procedure have to write to construct and print a table,
> where
> · the names of the nodes will appear in different rows and
> columns of
> the table and
> · the total arrangement will appear like a binary tree of the
> following figure.
> N0
> N1 N2
> N3
> N4 N5 N6
> N7 N8
>
Printing is a function for the client to deal with not SQL Server. How you
store and return the hierarchy/tree from SQL Server depends on the model you
are using e.g. nested set or adjacency. Joe Celko's Trees and Hierarchies
book ISBN 1-55860-920-2 (and there are plenty of posts on this!) will give
you some background on this. SQL Server 2005 has the ability for recursive
queries using CTEs which can be ustilised to traverse your hierarchy if you
are using this version.
John|||I believe one or more of Itzik Ben-Gan's books cover trees/graphs as well.
Very good reads.
TheSQLGuru
President
Indicium Resources, Inc.
"babu" <nasif4003@.gmail.com> wrote in message
news:1179497643.034074.249710@.p77g2000hsh.googlegroups.com...
Suppose there is a database table which contains information of a
complete binary tree.
A complete binary tree is always populated depth wise. A certain level
is filled up completely before going further level
down.
The table contains sequential information of the tree. As shown in the
following, the table on the right contains the tree information on the
left after inserting 4 nodes.
ID Name tree
1 N0 N0
2 N1
N1 N2
3 N2
And after inserting 4 nodes the table becomes as below.
ID Name Tree
1 N0 N0
2 N1 N1 N2
3 N2 N3
4 N3
Given a table containing the node information (the number of nodes is
arbitrary) of a complete binary tree as above.
A stored procedure have to write to construct and print a table,
where
the names of the nodes will appear in different rows and
columns of
the table and
the total arrangement will appear like a binary tree of the
following figure.
N0
N1 N2
N3
N4 N5 N6
N7 N8

A question related to stored procedure

Suppose there is a database table which contains information of a
complete binary tree.
A complete binary tree is always populated depth wise. A certain level
is filled up completely before going further level
down.
The table contains sequential information of the tree. As shown in the
following, the table on the right contains the tree information on the
left after inserting 4 nodes.
ID Name tree
1 N0 N0
2 N1
N1 N2
3 N2
And after inserting 4 nodes the table becomes as below.
ID Name Tree
1 N0 N0
2 N1 N1 N2
3 N2 N3
4 N3
Given a table containing the node information (the number of nodes is
arbitrary) of a complete binary tree as above.
A stored procedure have to write to construct and print a table,
where
=B7 the names of the nodes will appear in different rows and
columns of
the table and
=B7 the total arrangement will appear like a binary tree of the
following figure.
N0
N1 N2
N3
N4 N5 N6
N7 N8Hi
"babu" wrote:
> Suppose there is a database table which contains information of a
> complete binary tree.
> A complete binary tree is always populated depth wise. A certain level
> is filled up completely before going further level
> down.
> The table contains sequential information of the tree. As shown in the
> following, the table on the right contains the tree information on the
> left after inserting 4 nodes.
> ID Name tree
> 1 N0 N0
> 2 N1
> N1 N2
> 3 N2
> And after inserting 4 nodes the table becomes as below.
> ID Name Tree
> 1 N0 N0
> 2 N1 N1 N2
> 3 N2 N3
> 4 N3
> Given a table containing the node information (the number of nodes is
> arbitrary) of a complete binary tree as above.
> A stored procedure have to write to construct and print a table,
> where
> · the names of the nodes will appear in different rows and
> columns of
> the table and
> · the total arrangement will appear like a binary tree of the
> following figure.
> N0
> N1 N2
> N3
> N4 N5 N6
> N7 N8
>
Printing is a function for the client to deal with not SQL Server. How you
store and return the hierarchy/tree from SQL Server depends on the model you
are using e.g. nested set or adjacency. Joe Celko's Trees and Hierarchies
book ISBN 1-55860-920-2 (and there are plenty of posts on this!) will give
you some background on this. SQL Server 2005 has the ability for recursive
queries using CTEs which can be ustilised to traverse your hierarchy if you
are using this version.
John|||I believe one or more of Itzik Ben-Gan's books cover trees/graphs as well.
Very good reads.
--
TheSQLGuru
President
Indicium Resources, Inc.
"babu" <nasif4003@.gmail.com> wrote in message
news:1179497643.034074.249710@.p77g2000hsh.googlegroups.com...
Suppose there is a database table which contains information of a
complete binary tree.
A complete binary tree is always populated depth wise. A certain level
is filled up completely before going further level
down.
The table contains sequential information of the tree. As shown in the
following, the table on the right contains the tree information on the
left after inserting 4 nodes.
ID Name tree
1 N0 N0
2 N1
N1 N2
3 N2
And after inserting 4 nodes the table becomes as below.
ID Name Tree
1 N0 N0
2 N1 N1 N2
3 N2 N3
4 N3
Given a table containing the node information (the number of nodes is
arbitrary) of a complete binary tree as above.
A stored procedure have to write to construct and print a table,
where
· the names of the nodes will appear in different rows and
columns of
the table and
· the total arrangement will appear like a binary tree of the
following figure.
N0
N1 N2
N3
N4 N5 N6
N7 N8

A Question Regarding MSDE Desktop Engine

Dear all,

This week I was told to setup MSDE Desktop Engine on my pc bcz my Access back end db is getting bigger in size. And as a little advance step, I decided to put my Access back end on SQL server.

To be frank, I have no experience with SQL server but after reading the instructions, I have installed MSDE (latest version) on my pc successfully. A small icon of SQL server appeared nearby clock icon of my pc showing the SQL server is running on ASHFAQUEPC.

I shifted a Trial db onto this server in following way.

Considering the opened Trial db would be my BE, from the Tools--Database Utility--Upsize wizard, I followed below steps according to Upsize wizard.

1. I selected Local server and check marked to Use Trusted Connection.
2. And then I selected some tables to export
3. Kept all default attributes of db as it is
4. Selected Let the wizard decide under data option to include.
5. At the next step What application change do you want to make?
a. Create a new Access client/Server application.
b. Link SQL Server tables to existing application.
c. No application changes. (I selected this option)

Then it showed me the report of my db description of changes that were made after deploying it. The report I did not print bcz it was a trial db with one table (2 fields) and a simple query.

My idea was to connect my Trial BE with another one of another Access mdb file so FE would be Access and BE would be from MSDE.

1. Now I dont know how to link my BE to my FE?
2. From where I can directly see my BE? Because SQL Server Service Manager does
not have any menu?
3. Where I was wrong in following steps?

Guidance in this regards is highly appreciated.

With kind regards,
AshfaqueI got it.

The tables of db from MSDE2000A I can get connected thru database project file.

Thanks.
Ashfaque

a question or two re fulltext queries

hi,
i'm using SQL Server 2000 (SP3, I think).
i am looking at SQL for finding documents (table DOC) based on a couple of
criteria, one of which involves a fulltext index on a related table (TXT).
i discovered today that a less selective CONTAINS() clause:
CONTAINS (txt_stripped, 'daimler')
results in disastrous performance when I ask for the "top 10" documents
sorted by published date (a field of DOC) descending.
if I
1) include a more selective contains clause:
CONTAINS (txt_stripped, 'daimler AND mercedes')
2) omit the "top 10" (there are only125 documents total.) or
3) omit the "ORDER BY doc_pubfrom DESC" clause
the query performs fine.
i examined the query plans and discovered that in the bad case the first
thing done is to walk the doc_pubfrom index (figures, I guess: top 10 order
by...). in the other cases the first thing done is the "remote scan" of the
fulltext index, which is what I want done first.
i already know how I'll solve this problem: i don't need the "top 10" at
this point -- it was just a whim while prototyping.
my questions, though for future reference:
1) is there syntax to influence SQL's query planning specifically to prefer
the full text index ?
2) is there a way to get the query plan textually? (the graphic view is
great but I wondered what I would do if I wanted to mail it or post it)
cheers,
Tim Hanson
1) Could you post the entire schema with indexes?
2) use set showplan_text on
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"tbh" <femdev@.newsgroups.nospam> wrote in message
news:uTlE0P$KGHA.1180@.TK2MSFTNGP09.phx.gbl...
> hi,
> i'm using SQL Server 2000 (SP3, I think).
> i am looking at SQL for finding documents (table DOC) based on a couple of
> criteria, one of which involves a fulltext index on a related table (TXT).
> i discovered today that a less selective CONTAINS() clause:
> CONTAINS (txt_stripped, 'daimler')
> results in disastrous performance when I ask for the "top 10" documents
> sorted by published date (a field of DOC) descending.
> if I
> 1) include a more selective contains clause:
> CONTAINS (txt_stripped, 'daimler AND mercedes')
> 2) omit the "top 10" (there are only125 documents total.) or
> 3) omit the "ORDER BY doc_pubfrom DESC" clause
> the query performs fine.
> i examined the query plans and discovered that in the bad case the first
> thing done is to walk the doc_pubfrom index (figures, I guess: top 10
> order by...). in the other cases the first thing done is the "remote scan"
> of the fulltext index, which is what I want done first.
> i already know how I'll solve this problem: i don't need the "top 10" at
> this point -- it was just a whim while prototyping.
> my questions, though for future reference:
> 1) is there syntax to influence SQL's query planning specifically to
> prefer the full text index ?
> 2) is there a way to get the query plan textually? (the graphic view is
> great but I wondered what I would do if I wanted to mail it or post it)
> cheers,
> Tim Hanson
>
|||thanks, Hillary, that was quick!
re 1) by "schema" you mean all affected tables? that would be a serious
handful. i'd hate to trouble you and post so much stuff. do you have any
general hints on keywords for nudging the query plan in favor of fulltext
index first?
re 2) thanks!!
cheers,
Tim
"Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
news:OPg4yc$KGHA.668@.TK2MSFTNGP11.phx.gbl...
> 1) Could you post the entire schema with indexes?
> 2) use set showplan_text on
> --
> Hilary Cotter
|||Just the problem tables. I don't have any hints off the top of my head. You
might be able to do a force order query hint which might help.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"tbh" <femdev@.newsgroups.nospam> wrote in message
news:uyE2Ow$KGHA.4052@.TK2MSFTNGP15.phx.gbl...
> thanks, Hillary, that was quick!
> re 1) by "schema" you mean all affected tables? that would be a serious
> handful. i'd hate to trouble you and post so much stuff. do you have any
> general hints on keywords for nudging the query plan in favor of fulltext
> index first?
> re 2) thanks!!
> cheers,
> Tim
>
> "Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
> news:OPg4yc$KGHA.668@.TK2MSFTNGP11.phx.gbl...
>
>
|||I have the same problem, when I search for a (litle) word that apears
in many records, the query that uses full-text index takes to long to
execute.
I use Top 1000, Contains() and Order By.
How can I optimize this without changing the TOP and Order by?
Thaks
|||Can you use a containstable and the top_n_by_rank clause? IE
SELECT FT_TBL.Description,
FT_TBL.CategoryName,
KEY_TBL.RANK
FROM Categories AS FT_TBL INNER JOIN
CONTAINSTABLE (Categories, Description,
'("sweet and savory" NEAR sauces) OR
("sweet and savory" NEAR candies)'
, 10
) AS KEY_TBL
ON FT_TBL.CategoryID = KEY_TBL.[KEY]
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
<paulo.gonc@.gmail.com> wrote in message
news:1139421012.509817.170610@.g43g2000cwa.googlegr oups.com...
>I have the same problem, when I search for a (litle) word that apears
> in many records, the query that uses full-text index takes to long to
> execute.
> I use Top 1000, Contains() and Order By.
> How can I optimize this without changing the TOP and Order by?
> Thaks
>

A question on when to use bulk logged recovery mode

Hi all,
I was hoping that someone could tell me a couple of scenarios where the
bulk logged recovery mode is used and perhaps why?
I'm guessing you might use it just before doing a large data import, but
does that mean you might switch to it before the import and switch back
to full recovery once it's done? Is that a good idea?
What other instances might it be used? Perhaps in a reporting database
for some reason?
Many thanks to anyone who can advise
Kindest Regards
Simon
Simon
> I'm guessing you might use it just before doing a large data import, but
> does that mean you might switch to it before the import and switch back to
> full recovery once it's done? Is that a good idea?
BOL says
In Microsoft SQL ServerT 2000, you can switch between full and bulk-logged
recovery models easily. It is not necessary to perform a full database
backup after bulk copy operations complete under the Bulk-Logged Recovery
model. Transaction log backups under this model capture both the log and the
results of any bulk operations performed since the last backup.

> I was hoping that someone could tell me a couple of scenarios where the
> bulk logged recovery mode is used and perhaps why?
There are some operatuions like SELECT INTO..,CREATE INDEX under BULK
logged recovery mode are minimally loggged.
A disadvantage is that you cannot restore LOG file at point of time
"Simon Harvey" <nothanks@.hotmail.com> wrote in message
news:uz%23a2I2HHHA.1264@.TK2MSFTNGP06.phx.gbl...
> Hi all,
> I was hoping that someone could tell me a couple of scenarios where the
> bulk logged recovery mode is used and perhaps why?
> I'm guessing you might use it just before doing a large data import, but
> does that mean you might switch to it before the import and switch back to
> full recovery once it's done? Is that a good idea?
> What other instances might it be used? Perhaps in a reporting database for
> some reason?
> Many thanks to anyone who can advise
> Kindest Regards
> Simon

A question on when to use bulk logged recovery mode

Hi all,
I was hoping that someone could tell me a couple of scenarios where the
bulk logged recovery mode is used and perhaps why?
I'm guessing you might use it just before doing a large data import, but
does that mean you might switch to it before the import and switch back
to full recovery once it's done? Is that a good idea?
What other instances might it be used? Perhaps in a reporting database
for some reason?
Many thanks to anyone who can advise
Kindest Regards
SimonSimon
> I'm guessing you might use it just before doing a large data import, but
> does that mean you might switch to it before the import and switch back to
> full recovery once it's done? Is that a good idea?
BOL says
In Microsoft® SQL ServerT 2000, you can switch between full and bulk-logged
recovery models easily. It is not necessary to perform a full database
backup after bulk copy operations complete under the Bulk-Logged Recovery
model. Transaction log backups under this model capture both the log and the
results of any bulk operations performed since the last backup.
> I was hoping that someone could tell me a couple of scenarios where the
> bulk logged recovery mode is used and perhaps why?
There are some operatuions like SELECT INTO..,CREATE INDEX under BULK
logged recovery mode are minimally loggged.
A disadvantage is that you cannot restore LOG file at point of time
"Simon Harvey" <nothanks@.hotmail.com> wrote in message
news:uz%23a2I2HHHA.1264@.TK2MSFTNGP06.phx.gbl...
> Hi all,
> I was hoping that someone could tell me a couple of scenarios where the
> bulk logged recovery mode is used and perhaps why?
> I'm guessing you might use it just before doing a large data import, but
> does that mean you might switch to it before the import and switch back to
> full recovery once it's done? Is that a good idea?
> What other instances might it be used? Perhaps in a reporting database for
> some reason?
> Many thanks to anyone who can advise
> Kindest Regards
> Simon|||> I'm guessing you might use it just before doing a large data import, but does that mean you might
> switch to it before the import and switch back to full recovery once it's done? Is that a good
> idea?
Yes, this brings you the advantage of being in contold of when log backups which includes both log
recards and datapages can occur. Run in full normally, swith down the bulk logged only for this
batch and then up to full again. You are now protected against someone doing SELECT INTO at 3:15 pm
resuting in not being able to do point in time restore for the following log backup (just as an
example).
My take on this is that I weigh what bulk logged will atcually contribute. Will the operation be
faster (compared to full) to warrant bulk logged? And/or the fact that ldf file is smaller, is it
worth it? this need to be compared to the disadvantages (no point in time restore for such log
backup, and not being able to do log backup if for instance mdf file is gone). Also, you need to
think about how larger the following log backup is compared to run in full mode (either fewer log
records but also data pages, or only log records, but more of them).
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Simon Harvey" <nothanks@.hotmail.com> wrote in message
news:uz%23a2I2HHHA.1264@.TK2MSFTNGP06.phx.gbl...
> Hi all,
> I was hoping that someone could tell me a couple of scenarios where the bulk logged recovery mode
> is used and perhaps why?
> I'm guessing you might use it just before doing a large data import, but does that mean you might
> switch to it before the import and switch back to full recovery once it's done? Is that a good
> idea?
> What other instances might it be used? Perhaps in a reporting database for some reason?
> Many thanks to anyone who can advise
> Kindest Regards
> Simon

A question on when to use bulk logged recovery mode

Hi all,
I was hoping that someone could tell me a couple of scenarios where the
bulk logged recovery mode is used and perhaps why?
I'm guessing you might use it just before doing a large data import, but
does that mean you might switch to it before the import and switch back
to full recovery once it's done? Is that a good idea?
What other instances might it be used? Perhaps in a reporting database
for some reason?
Many thanks to anyone who can advise
Kindest Regards
SimonSimon
> I'm guessing you might use it just before doing a large data import, but
> does that mean you might switch to it before the import and switch back to
> full recovery once it's done? Is that a good idea?
BOL says
In Microsoft SQL ServerT 2000, you can switch between full and bulk-logged
recovery models easily. It is not necessary to perform a full database
backup after bulk copy operations complete under the Bulk-Logged Recovery
model. Transaction log backups under this model capture both the log and the
results of any bulk operations performed since the last backup.

> I was hoping that someone could tell me a couple of scenarios where the
> bulk logged recovery mode is used and perhaps why?
There are some operatuions like SELECT INTO..,CREATE INDEX under BULK
logged recovery mode are minimally loggged.
A disadvantage is that you cannot restore LOG file at point of time
"Simon Harvey" <nothanks@.hotmail.com> wrote in message
news:uz%23a2I2HHHA.1264@.TK2MSFTNGP06.phx.gbl...
> Hi all,
> I was hoping that someone could tell me a couple of scenarios where the
> bulk logged recovery mode is used and perhaps why?
> I'm guessing you might use it just before doing a large data import, but
> does that mean you might switch to it before the import and switch back to
> full recovery once it's done? Is that a good idea?
> What other instances might it be used? Perhaps in a reporting database for
> some reason?
> Many thanks to anyone who can advise
> Kindest Regards
> Simon|||> I'm guessing you might use it just before doing a large data import, but does that mean yo
u might
> switch to it before the import and switch back to full recovery once it's
done? Is that a good
> idea?
Yes, this brings you the advantage of being in contold of when log backups w
hich includes both log
recards and datapages can occur. Run in full normally, swith down the bulk l
ogged only for this
batch and then up to full again. You are now protected against someone doing
SELECT INTO at 3:15 pm
resuting in not being able to do point in time restore for the following log
backup (just as an
example).
My take on this is that I weigh what bulk logged will atcually contribute. W
ill the operation be
faster (compared to full) to warrant bulk logged? And/or the fact that ldf f
ile is smaller, is it
worth it? this need to be compared to the disadvantages (no point in time re
store for such log
backup, and not being able to do log backup if for instance mdf file is gone
). Also, you need to
think about how larger the following log backup is compared to run in full m
ode (either fewer log
records but also data pages, or only log records, but more of them).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Simon Harvey" <nothanks@.hotmail.com> wrote in message
news:uz%23a2I2HHHA.1264@.TK2MSFTNGP06.phx.gbl...
> Hi all,
> I was hoping that someone could tell me a couple of scenarios where the bu
lk logged recovery mode
> is used and perhaps why?
> I'm guessing you might use it just before doing a large data import, but d
oes that mean you might
> switch to it before the import and switch back to full recovery once it's
done? Is that a good
> idea?
> What other instances might it be used? Perhaps in a reporting database for
some reason?
> Many thanks to anyone who can advise
> Kindest Regards
> Simon

A question on subquery return

Here is subquery for a table, called pStatus

pStatus
userid
status

select 1 from pStatus where userid='Robert' and status='p'

How to modify this query so that it also return true if there is't an entry for userid 'Robert'?

Thanks,

vHow about:

where (not exists (select 1 from pStatus where userid='Robert')
or exists (select 1 from pStatus where userid='Robert' and status='p'))|||Thanks Tony.

That is quick and sharp one.

v.|||When I posted this question, I was thinking about using only one "select". The subquery is a small section of a long query with near 1,700 characters. And there are 10 similar subqueries in the query statement needed to have the same change. After running the planner, the performane doesn't seem too bad.

Nested Loop (cost=1.16..33.58 rows=1 width=398) (actual time=2.00..2.00 rows=0 loops=1)

...
Total runtime: 7.00 msec

Only few data at this moment.

v.

A Question on SQL Cluster -Urgent

We are planning the following setup as part of our Business Continuity
Planning.
We have an active passive cluster in the production and we will also have
the same setup in the DR setup. But the issue is that we need to keep the
same SQL virtual name in both Production and DR. So in this scenario if we
have to do some maintenance on the DR setup for eg: to apply Service Packs
or any fine tuning, how do we do that? Is there any recommendation or best
practices?
Waiting on an immediate response.
Abhi
Consider using a DNS alias. The apps use the alias, while the virtual
servers can be whatever you want.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
"Abhi" <Abhi@.discussions.microsoft.com> wrote in message
news:F4A782D4-8BD3-4B46-ABFA-B6BECE82908D@.microsoft.com...
We are planning the following setup as part of our Business Continuity
Planning.
We have an active passive cluster in the production and we will also have
the same setup in the DR setup. But the issue is that we need to keep the
same SQL virtual name in both Production and DR. So in this scenario if we
have to do some maintenance on the DR setup for eg: to apply Service Packs
or any fine tuning, how do we do that? Is there any recommendation or best
practices?
Waiting on an immediate response.
Abhi
|||"Abhi" <Abhi@.discussions.microsoft.com> wrote in message
news:F4A782D4-8BD3-4B46-ABFA-B6BECE82908D@.microsoft.com...
> We are planning the following setup as part of our Business Continuity
> Planning.
> We have an active passive cluster in the production and we will also have
> the same setup in the DR setup. But the issue is that we need to keep the
> same SQL virtual name in both Production and DR. So in this scenario if we
> have to do some maintenance on the DR setup for eg: to apply Service
> Packs
> or any fine tuning, how do we do that? Is there any recommendation or best
> practices?
You might also consider using database mirroring.
Russ Kaufmann
MVP - Windows Server - Clustering
ClusterHelp.com, a Microsoft Certified Gold Partner
Web http://www.clusterhelp.com
Blog http://msmvps.com/clusterhelp
The next ClusterHelp classes are:
July 10-13 in Denver
July 16-19 in New York
Sep 3 - 6 in Copenhagen

A question on ow to design some tables

Hi all,
I have a fairly tricky problem that I'm not sure how to approach.
I'm making a web application that manages drug trials. One of the
requirements of the system is if anyone makes changes to a field, the old
value and the new value need to be stored, along with the time of the change
and the reason for the change
The problem is I don't know how to support this for all the various fields
in all the various tables.
For example I have tables for storing basic patient details and then tables
for storing data on patient visits, patient screening data and so on.
Can anyone suggest how I could make a table or tables to store this audit
data for all the fields in all the tables? I'm not sure how to do it!
:-(
Thanks to anyone who can help
Simon
Hi Julie,
Thanks for your reply.
What I'm really stuck on is how to arrange the audit tables so that they can
store all sorts of information from the different types of data from all the
tables
Do you have any ideas along those lines?
Thanks again for your help!
Simon
|||What if you make duplicate tables and append "_archive" or similar to their
names, and use triggers to copy the original record in it's entirety to
these archive tables before inserting the new data into the main table?
"Simon Harvey" <simon.harvey@.the-web-works.co.uk> wrote in message
news:eexDr4VHEHA.2260@.TK2MSFTNGP09.phx.gbl...
> Hi Julie,
> Thanks for your reply.
> What I'm really stuck on is how to arrange the audit tables so that they
can
> store all sorts of information from the different types of data from all
the
> tables
> Do you have any ideas along those lines?
> Thanks again for your help!
> Simon
>
|||Hi Simon,
Keith has really answered the question. The best way I
have found how to do this is for every table you want to
audit, create an audit table.
In the example given to you two tables tblTesting is the
table the auditing is to take place, and tblTestAudit is
table where the changes will stored. You can cut paste and
run the code in Query Analyser and try it out if you want.
The example will capture every change made in the
tblTesting database and put the before and after values in
tblTestAudit.
What I actually showed you was quite basic, you can expand
it to show the name of the user who made the change, date
time of change, infact anything that can be programmed in.
So to recap.
1. The best way I have found is for each table you will to
audit create an audit table.
2. Cut and paste the demo, execute it in Query Analyser
and see what it does
3. Figure out what other things you need to change it.
Enjoy
J

>--Original Message--
>Hi Julie,
>Thanks for your reply.
>What I'm really stuck on is how to arrange the audit
tables so that they can
>store all sorts of information from the different types
of data from all the
>tables
>Do you have any ideas along those lines?
>Thanks again for your help!
>Simon
>
>.
>
|||Many thanks to both of you!
:-)
Simon

A question on ow to design some tables

Hi all,
I have a fairly tricky problem that I'm not sure how to approach.
I'm making a web application that manages drug trials. One of the
requirements of the system is if anyone makes changes to a field, the old
value and the new value need to be stored, along with the time of the change
and the reason for the change
The problem is I don't know how to support this for all the various fields
in all the various tables.
For example I have tables for storing basic patient details and then tables
for storing data on patient visits, patient screening data and so on.
Can anyone suggest how I could make a table or tables to store this audit
data for all the fields in all the tables? I'm not sure how to do it!
:-(
Thanks to anyone who can help
SimonHi Julie,
Thanks for your reply.
What I'm really stuck on is how to arrange the audit tables so that they can
store all sorts of information from the different types of data from all the
tables
Do you have any ideas along those lines?
Thanks again for your help!
Simon|||What if you make duplicate tables and append "_archive" or similar to their
names, and use triggers to copy the original record in it's entirety to
these archive tables before inserting the new data into the main table?
"Simon Harvey" <simon.harvey@.the-web-works.co.uk> wrote in message
news:eexDr4VHEHA.2260@.TK2MSFTNGP09.phx.gbl...
> Hi Julie,
> Thanks for your reply.
> What I'm really stuck on is how to arrange the audit tables so that they
can
> store all sorts of information from the different types of data from all
the
> tables
> Do you have any ideas along those lines?
> Thanks again for your help!
> Simon
>|||Hi Simon,
Keith has really answered the question. The best way I
have found how to do this is for every table you want to
audit, create an audit table.
In the example given to you two tables tblTesting is the
table the auditing is to take place, and tblTestAudit is
table where the changes will stored. You can cut paste and
run the code in Query Analyser and try it out if you want.
The example will capture every change made in the
tblTesting database and put the before and after values in
tblTestAudit.
What I actually showed you was quite basic, you can expand
it to show the name of the user who made the change, date
time of change, infact anything that can be programmed in.
So to recap.
1. The best way I have found is for each table you will to
audit create an audit table.
2. Cut and paste the demo, execute it in Query Analyser
and see what it does
3. Figure out what other things you need to change it.
Enjoy
J

>--Original Message--
>Hi Julie,
>Thanks for your reply.
>What I'm really stuck on is how to arrange the audit
tables so that they can
>store all sorts of information from the different types
of data from all the
>tables
>Do you have any ideas along those lines?
>Thanks again for your help!
>Simon
>
>.
>|||Many thanks to both of you!
:-)
Simon

A question on ow to design some tables

Hi all,
I have a fairly tricky problem that I'm not sure how to approach.
I'm making a web application that manages drug trials. One of the
requirements of the system is if anyone makes changes to a field, the old
value and the new value need to be stored, along with the time of the change
and the reason for the change
The problem is I don't know how to support this for all the various fields
in all the various tables.
For example I have tables for storing basic patient details and then tables
for storing data on patient visits, patient screening data and so on.
Can anyone suggest how I could make a table or tables to store this audit
data for all the fields in all the tables? I'm not sure how to do it!
:-(
Thanks to anyone who can help
SimonHi Simon,
There is an in built database utility called a Trigger,
these perform an automatic response for an INSERT, UPDATE
or DELETE.
You can access Triggers in EA by clicking on the 'Design'
of a table in EA, its the button next to primary key.
Anyway in the following example I have created three
triggers in a database table which stores the before and
after values in an audit table.
Give it a try and see if its what you want, you may also
want to read up about triggers on BOL.
J
CREATE TABLE [dbo].[tblTestAudit] (
[Type] [char] (6) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[ID] [int] NULL ,
[OldVal] [char] (20) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[NewVal] [char] (20) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[tblTesting] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[Testing] [char] (20) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblTesting] WITH NOCHECK ADD
CONSTRAINT [PK_tblTesting] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
GO
CREATE TRIGGER tk_INSERT ON [dbo].[tblTesting]
FOR INSERT
AS
DECLARE @.TKTYPE as char(6)
DECLARE @.ID as int
DECLARE @.NEW as char(20)
select @.ID = ID, @.NEW = Testing from inserted
insert into tblTestAudit (Type, ID, OldVal, NewVal) Values
('INSERT', @.ID, '', @.NEW)
GO
CREATE TRIGGER tk_DELETE ON [dbo].[tblTesting]
FOR DELETE
AS
DECLARE @.TKTYPE as char(6)
DECLARE @.ID as int
DECLARE @.OLD as char(20)
select @.ID = ID, @.OLD = Testing from deleted
insert into tblTestAudit (Type, ID, OldVal, NewVal) Values
('DELETE', @.ID, '@.OLD', '')
GO
CREATE TRIGGER tk_UPDATE ON [dbo].[tblTesting]
FOR UPDATE
AS
DECLARE @.TKTYPE as char(6)
DECLARE @.ID as int
DECLARE @.NEW as char(20)
DECLARE @.OLD as char(20)
select @.OLD = Testing from deleted
select @.ID = ID, @.NEW = Testing from inserted
insert into tblTestAudit (Type, ID, OldVal, NewVal) Values
('DELETE', @.ID, '@.OLD', '@.NEW')
>--Original Message--
>Hi all,
>I have a fairly tricky problem that I'm not sure how to
approach.
>I'm making a web application that manages drug trials.
One of the
>requirements of the system is if anyone makes changes to
a field, the old
>value and the new value need to be stored, along with the
time of the change
>and the reason for the change
>The problem is I don't know how to support this for all
the various fields
>in all the various tables.
>For example I have tables for storing basic patient
details and then tables
>for storing data on patient visits, patient screening
data and so on.
>Can anyone suggest how I could make a table or tables to
store this audit
>data for all the fields in all the tables? I'm not sure
how to do it!
>:-(
>Thanks to anyone who can help
>Simon
>
>.
>|||Hi Julie,
Thanks for your reply.
What I'm really stuck on is how to arrange the audit tables so that they can
store all sorts of information from the different types of data from all the
tables
Do you have any ideas along those lines?
Thanks again for your help!
Simon|||What if you make duplicate tables and append "_archive" or similar to their
names, and use triggers to copy the original record in it's entirety to
these archive tables before inserting the new data into the main table?
"Simon Harvey" <simon.harvey@.the-web-works.co.uk> wrote in message
news:eexDr4VHEHA.2260@.TK2MSFTNGP09.phx.gbl...
> Hi Julie,
> Thanks for your reply.
> What I'm really stuck on is how to arrange the audit tables so that they
can
> store all sorts of information from the different types of data from all
the
> tables
> Do you have any ideas along those lines?
> Thanks again for your help!
> Simon
>|||Hi Simon,
Keith has really answered the question. The best way I
have found how to do this is for every table you want to
audit, create an audit table.
In the example given to you two tables tblTesting is the
table the auditing is to take place, and tblTestAudit is
table where the changes will stored. You can cut paste and
run the code in Query Analyser and try it out if you want.
The example will capture every change made in the
tblTesting database and put the before and after values in
tblTestAudit.
What I actually showed you was quite basic, you can expand
it to show the name of the user who made the change, date
time of change, infact anything that can be programmed in.
So to recap.
1. The best way I have found is for each table you will to
audit create an audit table.
2. Cut and paste the demo, execute it in Query Analyser
and see what it does
3. Figure out what other things you need to change it.
Enjoy
J
>--Original Message--
>Hi Julie,
>Thanks for your reply.
>What I'm really stuck on is how to arrange the audit
tables so that they can
>store all sorts of information from the different types
of data from all the
>tables
>Do you have any ideas along those lines?
>Thanks again for your help!
>Simon
>
>.
>|||Many thanks to both of you!
:-)
Simon

A question on JOIN

Hi, guys,

I am confused by JOIN s. It said JOIN would hurt queryperformance. So is there some limit of number of JOIN s in a query, say if yourquery has more than 3 joins, the performance would be hurt? And why?

Is there an alternate method of JOIN? I tried sub query, itseems the execution plans are the same.

another option to join would be to use UNION, but I think the performance would be the same or possibly worse using that.

Your joins will be affected less if you can specify how it joins on more than one parameter (If I recall correctly)..

SELECT * FROM maintable mt

INNER JOIN table t ON t.ID= mt.ID AND t.another_parameter=mt.another_parameter AND t.secondparam=mt.second_param AND t.thisfield='whatever'

WHERE mt.thisfield='whatever'

The more you filter it down, the less the query will have to scan the dataobject for results.

|||

Well the maximum number of tables per select statement is 256 for SQL Server. NORMALLY joins will have better performance than sub-queries as joins use relational algebra. Some people will say they only use joins if they need a field from the table they are joining into, but i normally use them over a sub-query(there are situations where a subquery is fatser or needed).

Also it matters what you are joining on, if you join on a text field or a non indexed field it will hurt query performance.

|||

The speed of a JOIN is more influenced by the number of rows in both sources of the join, and the number of rows in the result. Using the correct indexes can speed up the JOIN. I've seen multi-minute queries sped up by a single index to sub-second responses by the correct use of indexes, and I'm sure there is even better results (and worse).

|||

As Motley points out, what matters are proper indexing and the actual number of rows being returned by tables in each join condition. I have had 8 table joins with sub-second response time where all the tables are being selected based on a primary key value.

There is no alternative to a join in the sense that if you have normalized data, you're going to have to join the tables to get the data. There is NO reason to avoid joins, even ones involving many tables.

|||

Got it.

Guys, Thanks.

|||

how bout creating the joins in a view as opposed to creating it in a stored procedure? will this improve performance?

|||

Not unless it's an indexed/materialized view, no.

A question on Isolation level

Whenever the update statment is executed the patient table will be
locked even for the querying. Is there a way
where in the select locks the table so that the other transaction will
not even able to select.
If change the isolation level to repeatable read or higher it will not
allow update and insert by other transaction
but select will be allowed which I want to stop
SQL
--
BEGIN TRAN
SELECT * FROM PATIENT WHERE STATUS = 'A'
WAITFOR DELAY '00:00:10'
UPDATE PATIENT SET STATUS = 'I' WHERE STATUS = 'A'
WAITFOR DELAY '00:00:10'
COMMIT TRANI don't understand why you have the waitfor statements. My understanding of
how the lock manager works is that it will escalate the number of locks it
has to place based on the indexes in place and the perceived numbers of rows
it has to update.
So if you have an index in place on the status column and only a few rows of
a large table have a value of A row level locking should occur. If there are
no indexes or depending on the number of rows, it could be page level,
extent locks or a table lock.
I would update statsitics, evaluate how many rows are affected to see if you
can't change this behavior.
--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"shiju" <shiju.samuel@.gmail.com> wrote in message
news:1156937237.329228.258100@.m73g2000cwd.googlegroups.com...
> Whenever the update statment is executed the patient table will be
> locked even for the querying. Is there a way
> where in the select locks the table so that the other transaction will
> not even able to select.
> If change the isolation level to repeatable read or higher it will not
> allow update and insert by other transaction
> but select will be allowed which I want to stop
>
> SQL
> --
> BEGIN TRAN
> SELECT * FROM PATIENT WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
> UPDATE PATIENT SET STATUS = 'I' WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
> COMMIT TRAN
>|||On 30 Aug 2006 04:27:17 -0700, "shiju" <shiju.samuel@.gmail.com> wrote:
>Whenever the update statment is executed the patient table will be
>locked even for the querying. Is there a way
>where in the select locks the table so that the other transaction will
>not even able to select.
>If change the isolation level to repeatable read or higher it will not
>allow update and insert by other transaction
>but select will be allowed which I want to stop
try "select * from patient with (updlock) where status = 'A'"
>
>SQL
>--
>BEGIN TRAN
> SELECT * FROM PATIENT WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
> UPDATE PATIENT SET STATUS = 'I' WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
>COMMIT TRAN

A question on Isolation level

Whenever the update statment is executed the patient table will be
locked even for the querying. Is there a way
where in the select locks the table so that the other transaction will
not even able to select.
If change the isolation level to repeatable read or higher it will not
allow update and insert by other transaction
but select will be allowed which I want to stop
SQL
--
BEGIN TRAN
SELECT * FROM PATIENT WHERE STATUS = 'A'
WAITFOR DELAY '00:00:10'
UPDATE PATIENT SET STATUS = 'I' WHERE STATUS = 'A'
WAITFOR DELAY '00:00:10'
COMMIT TRANI don't understand why you have the waitfor statements. My understanding of
how the lock manager works is that it will escalate the number of locks it
has to place based on the indexes in place and the perceived numbers of rows
it has to update.
So if you have an index in place on the status column and only a few rows of
a large table have a value of A row level locking should occur. If there are
no indexes or depending on the number of rows, it could be page level,
extent locks or a table lock.
I would update statsitics, evaluate how many rows are affected to see if you
can't change this behavior.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"shiju" <shiju.samuel@.gmail.com> wrote in message
news:1156937237.329228.258100@.m73g2000cwd.googlegroups.com...
> Whenever the update statment is executed the patient table will be
> locked even for the querying. Is there a way
> where in the select locks the table so that the other transaction will
> not even able to select.
> If change the isolation level to repeatable read or higher it will not
> allow update and insert by other transaction
> but select will be allowed which I want to stop
>
> SQL
> --
> BEGIN TRAN
> SELECT * FROM PATIENT WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
> UPDATE PATIENT SET STATUS = 'I' WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
> COMMIT TRAN
>|||On 30 Aug 2006 04:27:17 -0700, "shiju" <shiju.samuel@.gmail.com> wrote:

>Whenever the update statment is executed the patient table will be
>locked even for the querying. Is there a way
>where in the select locks the table so that the other transaction will
>not even able to select.
>If change the isolation level to repeatable read or higher it will not
>allow update and insert by other transaction
>but select will be allowed which I want to stop
try "select * from patient with (updlock) where status = 'A'"

>
>SQL
>--
>BEGIN TRAN
> SELECT * FROM PATIENT WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
> UPDATE PATIENT SET STATUS = 'I' WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
>COMMIT TRAN

A question on indexed views and the optimizer ...

Gentle SQL gurus,
Say I have a table "a" which has a column "ca". And I have a table "b"
which has a column "cb".
And I define a view "ajoinb" as
create view ajoinb as
select ..., a.ca, b.cb, ...
from a
inner join b
on b.fktoa = a.pk
And then I create an index on this view "ajoinb" as
create index "indexedviewonajoinb" on ajoinb (ca, cb)
Presumably if I run a query like
select ...
from ajoinb
where ca = <value a>
and cb = <value b>
then the optimizer will use the indexed view.
But what if the query is like this:
select ...
from a
inner join b
on b.fktoa = a.pk
where a.ca = <value a>
and b.cb = <value b>
Will the optimizer still use the index I created called
"indexedviewonajoinb" even though I am not explicitly doing the select
on the view "ajoinb"?
A second question: What is the data structure for an indexed view? For
a regular index you have a key and the value is a pointer to the
underlying table. For an indexed view does SQL server store one pointer
to each table in the view for each key in the index?
Thanks in advance for any and all help.
Regards,
Anil
> Will the optimizer still use the index I created called
> "indexedviewonajoinb" even though I am not explicitly doing the select
> on the view "ajoinb"?
Probably. But you need to test to make sure. Also, only on EE. On SE you must reference the view and
also use the NOEXPAND hint for the index on the view to be used.

> A second question: What is the data structure for an indexed view?
The first index you create in the view need to be both unique and clustered. So the structure is
just like any old clustered index. The key you define for this index on the view is what the index
is ordered on, and the other columns you have as "bonus" in the leaf level of that index.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
<sqlpractitioner@.gmail.com> wrote in message
news:1160671653.825698.82430@.i3g2000cwc.googlegrou ps.com...
> Gentle SQL gurus,
> Say I have a table "a" which has a column "ca". And I have a table "b"
> which has a column "cb".
> And I define a view "ajoinb" as
> create view ajoinb as
> select ..., a.ca, b.cb, ...
> from a
> inner join b
> on b.fktoa = a.pk
> And then I create an index on this view "ajoinb" as
> create index "indexedviewonajoinb" on ajoinb (ca, cb)
> Presumably if I run a query like
> select ...
> from ajoinb
> where ca = <value a>
> and cb = <value b>
> then the optimizer will use the indexed view.
> But what if the query is like this:
> select ...
> from a
> inner join b
> on b.fktoa = a.pk
> where a.ca = <value a>
> and b.cb = <value b>
> Will the optimizer still use the index I created called
> "indexedviewonajoinb" even though I am not explicitly doing the select
> on the view "ajoinb"?
> A second question: What is the data structure for an indexed view? For
> a regular index you have a key and the value is a pointer to the
> underlying table. For an indexed view does SQL server store one pointer
> to each table in the view for each key in the index?
> Thanks in advance for any and all help.
> Regards,
> Anil
>

A question on indexed views and the optimizer ...

Gentle SQL gurus,
Say I have a table "a" which has a column "ca". And I have a table "b"
which has a column "cb".
And I define a view "ajoinb" as
create view ajoinb as
select ..., a.ca, b.cb, ...
from a
inner join b
on b.fktoa = a.pk
And then I create an index on this view "ajoinb" as
create index "indexedviewonajoinb" on ajoinb (ca, cb)
Presumably if I run a query like
select ...
from ajoinb
where ca = <value a>
and cb = <value b>
then the optimizer will use the indexed view.
But what if the query is like this:
select ...
from a
inner join b
on b.fktoa = a.pk
where a.ca = <value a>
and b.cb = <value b>
Will the optimizer still use the index I created called
"indexedviewonajoinb" even though I am not explicitly doing the select
on the view "ajoinb"?
A second question: What is the data structure for an indexed view? For
a regular index you have a key and the value is a pointer to the
underlying table. For an indexed view does SQL server store one pointer
to each table in the view for each key in the index?
Thanks in advance for any and all help.
Regards,
Anil> Will the optimizer still use the index I created called
> "indexedviewonajoinb" even though I am not explicitly doing the select
> on the view "ajoinb"?
Probably. But you need to test to make sure. Also, only on EE. On SE you mus
t reference the view and
also use the NOEXPAND hint for the index on the view to be used.

> A second question: What is the data structure for an indexed view?
The first index you create in the view need to be both unique and clustered.
So the structure is
just like any old clustered index. The key you define for this index on the
view is what the index
is ordered on, and the other columns you have as "bonus" in the leaf level o
f that index.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
<sqlpractitioner@.gmail.com> wrote in message
news:1160671653.825698.82430@.i3g2000cwc.googlegroups.com...
> Gentle SQL gurus,
> Say I have a table "a" which has a column "ca". And I have a table "b"
> which has a column "cb".
> And I define a view "ajoinb" as
> create view ajoinb as
> select ..., a.ca, b.cb, ...
> from a
> inner join b
> on b.fktoa = a.pk
> And then I create an index on this view "ajoinb" as
> create index "indexedviewonajoinb" on ajoinb (ca, cb)
> Presumably if I run a query like
> select ...
> from ajoinb
> where ca = <value a>
> and cb = <value b>
> then the optimizer will use the indexed view.
> But what if the query is like this:
> select ...
> from a
> inner join b
> on b.fktoa = a.pk
> where a.ca = <value a>
> and b.cb = <value b>
> Will the optimizer still use the index I created called
> "indexedviewonajoinb" even though I am not explicitly doing the select
> on the view "ajoinb"?
> A second question: What is the data structure for an indexed view? For
> a regular index you have a key and the value is a pointer to the
> underlying table. For an indexed view does SQL server store one pointer
> to each table in the view for each key in the index?
> Thanks in advance for any and all help.
> Regards,
> Anil
>

A question on indexed views and the optimizer ...

Gentle SQL gurus,
Say I have a table "a" which has a column "ca". And I have a table "b"
which has a column "cb".
And I define a view "ajoinb" as
create view ajoinb as
select ..., a.ca, b.cb, ...
from a
inner join b
on b.fktoa = a.pk
And then I create an index on this view "ajoinb" as
create index "indexedviewonajoinb" on ajoinb (ca, cb)
Presumably if I run a query like
select ...
from ajoinb
where ca = <value a>
and cb = <value b>
then the optimizer will use the indexed view.
But what if the query is like this:
select ...
from a
inner join b
on b.fktoa = a.pk
where a.ca = <value a>
and b.cb = <value b>
Will the optimizer still use the index I created called
"indexedviewonajoinb" even though I am not explicitly doing the select
on the view "ajoinb"?
A second question: What is the data structure for an indexed view? For
a regular index you have a key and the value is a pointer to the
underlying table. For an indexed view does SQL server store one pointer
to each table in the view for each key in the index?
Thanks in advance for any and all help.
Regards,
Anil> Will the optimizer still use the index I created called
> "indexedviewonajoinb" even though I am not explicitly doing the select
> on the view "ajoinb"?
Probably. But you need to test to make sure. Also, only on EE. On SE you must reference the view and
also use the NOEXPAND hint for the index on the view to be used.
> A second question: What is the data structure for an indexed view?
The first index you create in the view need to be both unique and clustered. So the structure is
just like any old clustered index. The key you define for this index on the view is what the index
is ordered on, and the other columns you have as "bonus" in the leaf level of that index.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
<sqlpractitioner@.gmail.com> wrote in message
news:1160671653.825698.82430@.i3g2000cwc.googlegroups.com...
> Gentle SQL gurus,
> Say I have a table "a" which has a column "ca". And I have a table "b"
> which has a column "cb".
> And I define a view "ajoinb" as
> create view ajoinb as
> select ..., a.ca, b.cb, ...
> from a
> inner join b
> on b.fktoa = a.pk
> And then I create an index on this view "ajoinb" as
> create index "indexedviewonajoinb" on ajoinb (ca, cb)
> Presumably if I run a query like
> select ...
> from ajoinb
> where ca = <value a>
> and cb = <value b>
> then the optimizer will use the indexed view.
> But what if the query is like this:
> select ...
> from a
> inner join b
> on b.fktoa = a.pk
> where a.ca = <value a>
> and b.cb = <value b>
> Will the optimizer still use the index I created called
> "indexedviewonajoinb" even though I am not explicitly doing the select
> on the view "ajoinb"?
> A second question: What is the data structure for an indexed view? For
> a regular index you have a key and the value is a pointer to the
> underlying table. For an indexed view does SQL server store one pointer
> to each table in the view for each key in the index?
> Thanks in advance for any and all help.
> Regards,
> Anil
>

A Question on Database Restore

Dear All
I have a question on database restore in SQL server 2000.
I would like to restore a BAK file which is stored in another server. But
when i try to restore the BAK file through the restore wizard, i cannot find
the network drive and it can only show the local drive of the server.
Would you please kindly help to solve my problem, thanks a lot.
Kit
Try entering the UNC name of the shared drive and backup file directly in
the file name input box, assuming you have granted the appropriate
permissions. Alternatively, you could use the TSQL syntax directly e.g.
RESTORE DATABASE xx FROM DISK = '\\serverx\sharename'
(for a full database restore).
Peter Yeoh
http://www.yohz.com
Need smaller SQL2K backup files? Try MiniSQLBackup
"Kit" <yuck@.ha.org.hk> wrote in message
news:%23ukLxGBXEHA.3120@.TK2MSFTNGP12.phx.gbl...
> Dear All
> I have a question on database restore in SQL server 2000.
> I would like to restore a BAK file which is stored in another server. But
> when i try to restore the BAK file through the restore wizard, i cannot
find
> the network drive and it can only show the local drive of the server.
> Would you please kindly help to solve my problem, thanks a lot.
> Kit
>
|||To add to Peter's response, it is the SQL Server service account that needs
permissions to the share.
Hope this helps.
Dan Guzman
SQL Server MVP
"Kit" <yuck@.ha.org.hk> wrote in message
news:%23ukLxGBXEHA.3120@.TK2MSFTNGP12.phx.gbl...
> Dear All
> I have a question on database restore in SQL server 2000.
> I would like to restore a BAK file which is stored in another server. But
> when i try to restore the BAK file through the restore wizard, i cannot
find
> the network drive and it can only show the local drive of the server.
> Would you please kindly help to solve my problem, thanks a lot.
> Kit
>

A Question on Database Restore

Dear All
I have a question on database restore in SQL server 2000.
I would like to restore a BAK file which is stored in another server. But
when i try to restore the BAK file through the restore wizard, i cannot find
the network drive and it can only show the local drive of the server.
Would you please kindly help to solve my problem, thanks a lot.
KitTry entering the UNC name of the shared drive and backup file directly in
the file name input box, assuming you have granted the appropriate
permissions. Alternatively, you could use the TSQL syntax directly e.g.
RESTORE DATABASE xx FROM DISK = '\\serverx\sharename'
(for a full database restore).
Peter Yeoh
http://www.yohz.com
Need smaller SQL2K backup files? Try MiniSQLBackup
"Kit" <yuck@.ha.org.hk> wrote in message
news:%23ukLxGBXEHA.3120@.TK2MSFTNGP12.phx.gbl...
> Dear All
> I have a question on database restore in SQL server 2000.
> I would like to restore a BAK file which is stored in another server. But
> when i try to restore the BAK file through the restore wizard, i cannot
find
> the network drive and it can only show the local drive of the server.
> Would you please kindly help to solve my problem, thanks a lot.
> Kit
>|||To add to Peter's response, it is the SQL Server service account that needs
permissions to the share.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Kit" <yuck@.ha.org.hk> wrote in message
news:%23ukLxGBXEHA.3120@.TK2MSFTNGP12.phx.gbl...
> Dear All
> I have a question on database restore in SQL server 2000.
> I would like to restore a BAK file which is stored in another server. But
> when i try to restore the BAK file through the restore wizard, i cannot
find
> the network drive and it can only show the local drive of the server.
> Would you please kindly help to solve my problem, thanks a lot.
> Kit
>

A question on database design

Hi everyone,
I'm hoping someone could give me some advice on how to achieve the following.
I'm making a system that stores information on holiday homes. In particular
I need to store information on their bookings. When is a home occupied and
for how long.
I've considered making a Bookings table which would be somthing like:
ID
HomeID
StartDate
EndDate
What I can't see yet is how I'm going to query this table to find all properties
that are available for a given period.
What I want to be able to say is show me all homes that are available between
the 12th of april and the 27th of April.
Can anyone suggest how that query would work? Or is there perhaps a better
way to store this booking information?
Any advice and suggestions would be gratefully received.
Kindest Regards
Simon
> I've considered making a Bookings table which would be somthing like:
> ID
How about BookingID? ID is meaningless and can easily be taken out of
context.

> What I can't see yet is how I'm going to query this table to find all
> properties that are available for a given period.

> What I want to be able to say is show me all homes that are available
> between the 12th of april and the 27th of April.
-- untested, due to lack of DDL, sample data, desired results;
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND
(
b.StartDate BETWEEN @.startDate AND @.endDate
OR
b.EndDate BETWEEN @.startDate AND @.endDate
)
);
|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.
Don't you need a few more things in Bookings?
CREATE TABLE Bookings
(customer_id INTEGER NOT NULL
REFERENCES Customers(customer_id),
property_id INTEGER NOT NULL
REFERENCES Properties (property_id),
start_date DATETIME NOT NULL,
end_date DATETIME,
CHECK (start_date < end_date),
rental_rate DECIMAL (8,2) NOT NULL
CHECK (rental_rate > 0.00),
PRIMARY KEY (customer_id, property_id, start_date));
[vbcol=seagreen]
the 12th of April and the 27th of April. <<
I would build a Calendar table which is discussed in a lot of old
postings.
SELECT @.my_arrival, @.my_depart, P.property_id
FROM Properties AS P
WHERE NOT EXISTS
(SELECT *
FROM Bookings AS B,
Calendar AS C
WHERE C.cal_date
BETWEEN B.start_date AND B.end_date
AND B.property_id = P.property_id
AND cal_date BETWEEN @.my_arrival AND @.my_depart);
Untested.
(SELECT cal_date
FROM Calendar
WHERE cal_date BETWEEN @.my_arrival AND @.my_depart) AS X(cal_date)
|||You should consider recording dates for which a given unit is actually
available. One way is to create "fake" bookings for non-availability
dates - but that can get ugly.
|||On Tue, 17 Jan 2006 07:28:49 -0800, Simon Harvey wrote:
(snip)
>Can anyone suggest how that query would work? Or is there perhaps a better
>way to store this booking information?
Hi Simon,
Depending on your indexes, the query below might run faster than the
query Aaron suggests:
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND b.StartDate <= @.endDate
AND b.EndDate >= @.startDate
);
NOTE: I've set the follow-up to just the SQL Server groups. I can't help
with Access syntax anyway.
Hugo Kornelis, SQL Server MVP
|||Hi everyone
[vbcol=seagreen]
context.
Actually, the primary key in my tables is always ID, that way you never have
to think about it. I used to do it the other way, but then I got to thinking,
why call it BookingID? It's obviously a BookingID by virtue of the fact that
its the ID of the Booking table. I always fully qualify column names anyway
so I use Bookings.ID. I've heard some people say that doing this makes things
faster but I don't really care. I just do it for clarity and to avoid conflicts.
Of course if I was dealing with a foregin key in a table then I'd call it
BookingID because that would be implicitly helpful and quite necessary.
[vbcol=seagreen]
Declarative Referential Integrity, data types, etc. in your schema are. Sample
data is also a good idea, along with clear specifications. It is very hard
to debug code when you do not let us see it."
Well that would be difficult considering I don't have any DDL to offer. I
was asking a general queston on how to achieve an end goal. I suggested a
bookings table which was remarkably simple and existed only in my head. I
thought it was simple enough to be clear to those who saw the possible columns.
Thank you to everyone who has given some suggestions. I think I was pretty
much getting to the same conclusion as Aarons suggestion, but thats solidified
it in my mind.
Thanks again
Simon

A question on database design

Hi everyone,
I'm hoping someone could give me some advice on how to achieve the following
.
I'm making a system that stores information on holiday homes. In particular
I need to store information on their bookings. When is a home occupied and
for how long.
I've considered making a Bookings table which would be somthing like:
ID
HomeID
StartDate
EndDate
What I can't see yet is how I'm going to query this table to find all proper
ties
that are available for a given period.
What I want to be able to say is show me all homes that are available betwee
n
the 12th of april and the 27th of April.
Can anyone suggest how that query would work? Or is there perhaps a better
way to store this booking information?
Any advice and suggestions would be gratefully received.
Kindest Regards
Simon> I've considered making a Bookings table which would be somthing like:
> ID
How about BookingID? ID is meaningless and can easily be taken out of
context.

> What I can't see yet is how I'm going to query this table to find all
> properties that are available for a given period.

> What I want to be able to say is show me all homes that are available
> between the 12th of april and the 27th of April.
-- untested, due to lack of DDL, sample data, desired results;
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND
(
b.StartDate BETWEEN @.startDate AND @.endDate
OR
b.EndDate BETWEEN @.startDate AND @.endDate
)
);|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.
Don't you need a few more things in Bookings?
CREATE TABLE Bookings
(customer_id INTEGER NOT NULL
REFERENCES Customers(customer_id),
property_id INTEGER NOT NULL
REFERENCES Properties (property_id),
start_date DATETIME NOT NULL,
end_date DATETIME,
CHECK (start_date < end_date),
rental_rate DECIMAL (8,2) NOT NULL
CHECK (rental_rate > 0.00),
PRIMARY KEY (customer_id, property_id, start_date));
the 12th of April and the 27th of April. <<
I would build a Calendar table which is discussed in a lot of old
postings.
SELECT @.my_arrival, @.my_depart, P.property_id
FROM Properties AS P
WHERE NOT EXISTS
(SELECT *
FROM Bookings AS B,
Calendar AS C
WHERE C.cal_date
BETWEEN B.start_date AND B.end_date
AND B.property_id = P.property_id
AND cal_date BETWEEN @.my_arrival AND @.my_depart);
Untested.
(SELECT cal_date
FROM Calendar
WHERE cal_date BETWEEN @.my_arrival AND @.my_depart) AS X(cal_date)|||You should consider recording dates for which a given unit is actually
available. One way is to create "fake" bookings for non-availability
dates - but that can get ugly.|||On Tue, 17 Jan 2006 07:28:49 -0800, Simon Harvey wrote:
(snip)
>Can anyone suggest how that query would work? Or is there perhaps a better
>way to store this booking information?
Hi Simon,
Depending on your indexes, the query below might run faster than the
query Aaron suggests:
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND b.StartDate <= @.endDate
AND b.EndDate >= @.startDate
);
NOTE: I've set the follow-up to just the SQL Server groups. I can't help
with Access syntax anyway.
Hugo Kornelis, SQL Server MVP|||Hi everyone
context.
Actually, the primary key in my tables is always ID, that way you never have
to think about it. I used to do it the other way, but then I got to thinking
,
why call it BookingID? It's obviously a BookingID by virtue of the fact that
its the ID of the Booking table. I always fully qualify column names anyway
so I use Bookings.ID. I've heard some people say that doing this makes thing
s
faster but I don't really care. I just do it for clarity and to avoid confli
cts.
Of course if I was dealing with a foregin key in a table then I'd call it
BookingID because that would be implicitly helpful and quite necessary.
Declarative Referential Integrity, data types, etc. in your schema are. Samp
le
data is also a good idea, along with clear specifications. It is very hard
to debug code when you do not let us see it."
Well that would be difficult considering I don't have any DDL to offer. I
was asking a general queston on how to achieve an end goal. I suggested a
bookings table which was remarkably simple and existed only in my head. I
thought it was simple enough to be clear to those who saw the possible colum
ns.
Thank you to everyone who has given some suggestions. I think I was pretty
much getting to the same conclusion as Aarons suggestion, but thats solidifi
ed
it in my mind.
Thanks again
Simon

A question on database design

Hi everyone,
I'm hoping someone could give me some advice on how to achieve the following
.
I'm making a system that stores information on holiday homes. In particular
I need to store information on their bookings. When is a home occupied and
for how long.
I've considered making a Bookings table which would be somthing like:
ID
HomeID
StartDate
EndDate
What I can't see yet is how I'm going to query this table to find all proper
ties
that are available for a given period.
What I want to be able to say is show me all homes that are available betwee
n
the 12th of april and the 27th of April.
Can anyone suggest how that query would work? Or is there perhaps a better
way to store this booking information?
Any advice and suggestions would be gratefully received.
Kindest Regards
Simon> I've considered making a Bookings table which would be somthing like:
> ID
How about BookingID? ID is meaningless and can easily be taken out of
context.

> What I can't see yet is how I'm going to query this table to find all
> properties that are available for a given period.

> What I want to be able to say is show me all homes that are available
> between the 12th of april and the 27th of April.
-- untested, due to lack of DDL, sample data, desired results;
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND
(
b.StartDate BETWEEN @.startDate AND @.endDate
OR
b.EndDate BETWEEN @.startDate AND @.endDate
)
);|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.
Don't you need a few more things in Bookings?
CREATE TABLE Bookings
(customer_id INTEGER NOT NULL
REFERENCES Customers(customer_id),
property_id INTEGER NOT NULL
REFERENCES Properties (property_id),
start_date DATETIME NOT NULL,
end_date DATETIME,
CHECK (start_date < end_date),
rental_rate DECIMAL (8,2) NOT NULL
CHECK (rental_rate > 0.00),
PRIMARY KEY (customer_id, property_id, start_date));
[vbcol=seagreen]
the 12th of April and the 27th of April. <<
I would build a Calendar table which is discussed in a lot of old
postings.
SELECT @.my_arrival, @.my_depart, P.property_id
FROM Properties AS P
WHERE NOT EXISTS
(SELECT *
FROM Bookings AS B,
Calendar AS C
WHERE C.cal_date
BETWEEN B.start_date AND B.end_date
AND B.property_id = P.property_id
AND cal_date BETWEEN @.my_arrival AND @.my_depart);
Untested.
(SELECT cal_date
FROM Calendar
WHERE cal_date BETWEEN @.my_arrival AND @.my_depart) AS X(cal_date)|||You should consider recording dates for which a given unit is actually
available. One way is to create "fake" bookings for non-availability
dates - but that can get ugly.|||On Tue, 17 Jan 2006 07:28:49 -0800, Simon Harvey wrote:
(snip)
>Can anyone suggest how that query would work? Or is there perhaps a better
>way to store this booking information?
Hi Simon,
Depending on your indexes, the query below might run faster than the
query Aaron suggests:
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND b.StartDate <= @.endDate
AND b.EndDate >= @.startDate
);
NOTE: I've set the follow-up to just the SQL Server groups. I can't help
with Access syntax anyway.
Hugo Kornelis, SQL Server MVP|||Hi everyone
[vbcol=seagreen]
context.
Actually, the primary key in my tables is always ID, that way you never have
to think about it. I used to do it the other way, but then I got to thinking
,
why call it BookingID? It's obviously a BookingID by virtue of the fact that
its the ID of the Booking table. I always fully qualify column names anyway
so I use Bookings.ID. I've heard some people say that doing this makes thing
s
faster but I don't really care. I just do it for clarity and to avoid confli
cts.
Of course if I was dealing with a foregin key in a table then I'd call it
BookingID because that would be implicitly helpful and quite necessary.
[vbcol=seagreen]
Declarative Referential Integrity, data types, etc. in your schema are. Samp
le
data is also a good idea, along with clear specifications. It is very hard
to debug code when you do not let us see it."
Well that would be difficult considering I don't have any DDL to offer. I
was asking a general queston on how to achieve an end goal. I suggested a
bookings table which was remarkably simple and existed only in my head. I
thought it was simple enough to be clear to those who saw the possible colum
ns.
Thank you to everyone who has given some suggestions. I think I was pretty
much getting to the same conclusion as Aarons suggestion, but thats solidifi
ed
it in my mind.
Thanks again
Simon