Sliding Window Scenario For Shifting Partitions...do All Indexes Need To Be Built On The Staging Tables?

Oct 31, 2007

Kimberly Tripp describes a recipe for switching partitions in and out, thru the use of staging tables, when it comes time to "slide the window" on a partitioned table. She says that the clustered index (on staging) must be the same as that chosen for the partitioned table itself but she doesnt discuss whether or not all of the non clustered indexes need to be the same too once the
ALTER TABLE Orders
SWITCH PARTITION 1
TO OrdersOctober2002
and
ALTER TABLE OrdersOctober2004
SWITCH TO Orders PARTITION 24
run. For the data being switched out, I wouldnt want to do anything extra. For the data being switched in, I'd like to understand if she is implying that all other indexes would be built automatically as a result of the 2nd ALTER statement?

Kimberly's article is at http://www.sqlskills.com/resources/Whitepapers/Partitioning%20in%20SQL%20Server%202005%20Beta%20II.htm#_Toc79339965

View 1 Replies


ADVERTISEMENT

Sliding Window Scenario On Partitioned Table

Nov 13, 2007

I began with a partition function as follows:

CREATE PARTITION FUNCTION [TimeTicksRangePFN](bigint) AS RANGE RIGHT FOR VALUES (633294720000000000, 633320640000000000, 633347424000000000, 633374208000000000, 633399264000000000)

These numbers happen to correspond to the dates 11/1/7, 12/1/7, 1/1/8, 2/1/8 and 3/1/8 in ticks respectively.

I began with a partition scheme as follows:

CREATE PARTITION SCHEME [TimeTicksRangePScheme] AS PARTITION [TimeTicksRangePFN] TO ([FG_xxx_EventArchive00001], [FG_xxx_EventArchive00002], [FG_xxx_EventArchive00003], [FG_xxx_EventArchive00004], [FG_xxx_EventArchive00005], [PRIMARY])

While running my “sliding window script� , which I hoped would 1) roll off the oldest partition of my EventArchive table and 2) add a new partition with a tick boundary that equates to 3/5/8, I get an error related to my switch out table's index, the same table's Filegroup and Primary.

After getting the error, I scripted the partition function as a create in mgt studio and got…

CREATE PARTITION FUNCTION [TimeTicksRangePFN](bigint) AS RANGE RIGHT FOR VALUES (633320640000000000, 633347424000000000, 633374208000000000, 633399264000000000, 633402720000000000)

...which looks like what I had intended cuz the last boundary is the tick representation of 3/5/8 and the oldest has rolled off

scripting the scheme produced...

CREATE PARTITION SCHEME [TimeTicksRangePScheme] AS PARTITION [TimeTicksRangePFN] TO ([FG_xxx_EventArchive00001], [FG_xxx_EventArchive00003], [FG_xxx_EventArchive00004], [FG_xxx_EventArchive00005], [PRIMARY], [FG_xxx_EventArchive00001])

which looks nothing like what I intended, I thought I’d end up with …00002,…00003,…00004,…00005,…00001,PRIMARY

the script steps that seem most relevant start at the 5th step as follows...

5) creates table [dbo].Switch on the switch out filegroup with columns, PK and indexes matching exactly those of [dbo].EventArchive

6) switches partition 1 of [dbo].EventArchive to [dbo].Switch

7) ALTER PARTITION FUNCTION TimeTicksRangePFN() MERGE RANGE (633294720000000000) --this was the oldest date corresponding to 11/1/7

8) truncates [dbo].Switch

9) drops all indexes on [dbo].Switch except a clustered index (IX_TimeTicks), leaves PK constraint alone

10) ships the new data whose values range from 3/1/8 to less than 3/5/8 to [dbo].Switch and deletes them from their source

11) recreates all non clustered indexes on [dbo].Switch

12)ALTER TABLE [dbo].[Switch] WITH CHECK ADD CONSTRAINT RangeCK CHECK ([TimeTicks] < the number of ticks represented by 3/5/8)

13)ALTER PARTITION SCHEME TimeTicksRangePScheme NEXT USED [FG_xxx_EventArchive00001] --fg isnt really hardcoded

14)ALTER PARTITION FUNCTION TimeTicksRangePFN() SPLIT RANGE (the number of ticks represented by 3/5/8)

15)ALTER TABLE [dbo].[Switch] SWITCH TO [dbo].[EventArchive] PARTITION 5

step 15 is the one that fails with message "ALTER TABLE SWITCH statement failed. index 'xxx.dbo.Switch.IX_TimeTicks' is in filegroup 'FG_xxx_EventArchive00001' and partition 5 of index 'xxx.dbo.EventArchive.IX_TimeTicks' is in filegroup 'PRIMARY'.

View 1 Replies View Related

Problem With Sliding Window Scenario On Partitioned Table...

Nov 7, 2007

I have a partition function as follows:
CREATE PARTITION FUNCTION [TimeTicksRangePFN](bigint) AS RANGE RIGHT FOR VALUES (633294720000000000, 633320640000000000, 633347424000000000, 633374208000000000, 633399264000000000)

These numbers happen to correspond to the dates 11/1/7, 12/1/7, 1/1/8, 2/1/8 and 3/1/8 in ticks respectively.

I have a partition scheme as follows:
CREATE PARTITION SCHEME [TimeTicksRangePScheme] AS PARTITION [TimeTicksRangePFN] TO ([FG_xxx_EventArchive00001], [FG_xxx_EventArchive00002], [FG_xxx_EventArchive00003], [FG_xxx_EventArchive00004], [FG_xxx_EventArchive00005], [PRIMARY])

After running my €śsliding window script€? , which I wanted to switch out the lowest partition with, and add a new partition with a new tick boundary that equates to 3/5/8, I get an error saying that 1 of my switch out table€™s indexes is in filegroup 1 but partition 5€™s index of the same name is in PRIMARY. At this point the partition function looks like€¦

CREATE PARTITION FUNCTION [TimeTicksRangePFN](bigint) AS RANGE RIGHT FOR VALUES (633320640000000000, 633347424000000000, 633374208000000000, 633399264000000000, 633402720000000000) which looks like what I had intended cuz the last boundary is tick representation of 3/5/8 and the oldest has rolled off

and the scheme looks like€¦

CREATE PARTITION SCHEME [TimeTicksRangePScheme] AS PARTITION [TimeTicksRangePFN] TO ([FG_xxx_EventArchive00001], [FG_xxx_EventArchive00003], [FG_xxx_EventArchive00004], [FG_xxx_EventArchive00005], [PRIMARY], [FG_xxx_EventArchive00001]) which looks nothing like what I intended, I thought I€™d end up with €¦00002,€¦00003,€¦00004,€¦00005,€¦00001,PRIMARY

the relevant script steps are...

5) creates table [dbo].Switch on the switch out filegroup with columns, PK and indexes matching those of [dbo].EventArchive (allows default location for indexes)
6) switches partition 1 of [dbo].EventArchive to [dbo].Switch
7) ALTER PARTITION FUNCTION TimeTicksRangePFN() MERGE RANGE (633294720000000000)
8) truncates [dbo].Switch
9) drops all indexes on [dbo].Switch except a clustered index (IX_TimeTicks), leaves PK constraint alone
10) ships the new data whose values range from 3/1/8 to less than 3/5/8 to [dbo].Switch and deletes them from their source
11) recreates all non clustered indexes on [dbo].Switch
12)ALTER TABLE [dbo].[Switch] WITH CHECK ADD CONSTRAINT RangeCK CHECK ([TimeTicks] < the number of ticks represented by 3/5/8)
13)ALTER PARTITION SCHEME TimeTicksRangePScheme NEXT USED [FG_xxx_EventArchive00001]
14)ALTER PARTITION FUNCTION TimeTicksRangePFN() SPLIT RANGE (the number of ticks represented by 3/5/8)
15)ALTER TABLE [dbo].[Switch] SWITCH TO [dbo].[EventArchive] PARTITION 5

step 15 is the one that fails with message "ALTER TABLE SWITCH statement failed. index 'xxx.dbo.Switch.IX_TimeTicks' is in filegroup 'FG_xxx_EventArchive00001' and partition 5 of index 'xxx.dbo.EventArchive.IX_TimeTicks' is in filegroup 'PRIMARY'.

View 5 Replies View Related

SQL Server 2008 :: Partition Sliding Window Causing Loads Of Blocks

Oct 29, 2015

We have a massive database with an almost massive amount of traffic to and from it.

I've been requested to implement a sliding window partitioning with 2 partitions an active and passive 1,I managed to test this on a very small testbed last month.

I currently moved 97k table on to the partition function leaving me another 26 k to go

I'm using the following stored procedure to implement the sliding window

CREATE PROCEDURE [dbo].[ManageFactSlidingWindow](@pFunction nvarchar(max),@pSchema nvarchar(max),@FG nvarchar(max),@moveDays int)
/*****************************************************************************
PROCEDURE NAME: [ManageFactSlidingWindow]
AUTHOR: Arshad Ali
CREATED: 02/24/2013
DESCRIPTION: This stored procedure manages sliding window for the partitioned table

VERSION HISTORY:
DATE EMAIL Company DESCRIPTION

[Code] .....

When I try to move the partition even a single day I get loads of locks.

View 0 Replies View Related

Moving Indexes To Seperate Partitions

Jul 8, 1999

I have been asked to move the indexes on our membership database tables to seperate partitions on the server. This is a new concept to me and thought I could use some advice on how to go about doing it.

Thanks in advance.

Brad Keck

View 2 Replies View Related

SQL Server 2008 :: Usage Of Built-in Functions On Columns Ignores / Excludes Indexes On That Column?

May 25, 2015

Somewhere i read..that in SQL Server...usage of Built-in Functions on Columns, makes query optimizer to ignore indexes on that column...!

So lets say we have table EMP with Emp_id and Emp_Name....

Also we have Non-Clustered index on Emp_Name.

So following query would NOT use Non-Clustered index on Emp_Name column.

SELECTLEFT(emp_name, 3) as emp3
FROMdbo.EMP

Is this true? i am using SQL Server 2008.

View 4 Replies View Related

DBREINDEX Or INDEXDEFRAG Of A Few Indexes/window

Mar 31, 2007

I have a quite big database (150GB) that is running 24/24 7/7 with each day 2 windows of about 2 hours in which people are working little.
So doing a complete indexrebuild during the weekend is not possible. The only option is the rebuild/defrag indexes is during those windows. Problem is:I can't do it on all tables because it takes too much time.
So I was thinking about creating several SQL scripts and each of those is doing some tables/indexes. Problem is that I have a few hundreds of tables and if I want to move an index from 1 window to another, I have to change those scripts manually. Quite a time costing and error-prone procedure.

So I was hoping there is some tool that shows me all existing indexes and give me the possibility to add them to a script and once I have done that, generate the scripts to be run.
I have launched some searches on the forum but I didn't find any mentioning of the existence of such a tool.
Does someone know of such a tool or have a better idea how to do this?

Thanks,
Alain Krikilion

IF Debugging = removing bugs from program THEN programming := putting bugs in program;

View 3 Replies View Related

Staging Tables

Dec 7, 2005

I've found staging tables to still be necessary (for example, when you have a large dimension table that you can't load into memory.  The memory restricted lookup is too slow as it sends a query for each row).  I have a few questions:

View 7 Replies View Related

Data Warehousing :: Copy Data From Staging Tables To Other Instance Master Tables?

Aug 14, 2015

I need to copy data from warehouse tables to master tables of different SQL instances. Refresh need to done once in an hour. What is the best way to do this? SQL agent jobs or SSIS packages?

View 3 Replies View Related

Can Data Partitions Be Used With Associative Tables?

Aug 1, 2006

First of all, we are using SQL Server 2005 with a SQL Mobile subscriber and we are attempting to use Data Partitions on our current database
schema which contains associative tables for many-to-many relationships.

We have two tables, a User table
and an Audit table. A user can be
assigned more than one Audit. An Audit
can be assigned to more than one User.
So an AuditUser associative table exists. If data partitions are used based on User,
then any Audits that are assigned to one or more users should be copied to the
proper partition for each User (the msmerge_current_partition_mappings table
with the proper partition_id values).



In order to insert records with such a schema, the following
steps occur in order:

Insert
new row into Audit table with new rowguidInsert
entry into AuditUser table associating the auditguid with every userguid that
is assigned this audit.



Merge replication triggers are fired on insert of the Audit
row and another one for the insert of the AuditUser row.



When the Audit row is inserted, the replication trigger follows
the following logic:

Inserts
a copy of that row into the msmerge_contents table. Evaluates
the row to determine which partition(s) this row should be copied to as
well (msmerge_current_partition_mappings table). To do this, it checks to see if the
AuditGuid is referenced in one or more AuditUser rows. Since we haven€™t inserted the AuditUser
row at this point, the trigger€™s logic doesn€™t find a partition to copy
this row to.



When the AuditUser row is inserted, the replication trigger performs
the same logic as with the Audit row, it:

Inserts
a copy of that row into the msmerge_contents table.Evaluates
the row to determine which partition(s) this row should be copied to as
well (msmerge_current_partition_mappings table). Since the row meets the criteria for one
or more partitions, it is copied to the msmerge_current_partition_mappings
table for each partition that exists.



When replication occurs, we see only the AuditUser rows
copied down to our device, and not the corresponding Audit rows. Now that we understand the triggers, it is
plain to see why. If the AuditUser row
could be inserted first, then the trigger on the Audit row would copy that row
into the proper partitions and all would work well. However, the Audit row must be inserted
first, so that foreign key relationship constraints are preserved.



It seems that the Update trigger on the AuditUser row
actually walks the relationships and copies any related child rows to the
msmerge_current_partition_mappings table.

View 3 Replies View Related

Table Partitions On Existing Tables.

Jun 4, 2007

Hi guys , assuming right now I already create partition function (PF_Date) and partition scheme (PS_Date). Let say I would like to implement the partition on the existing tables ( eg: transaction table which is in PRIMARY filegroup), how am I switch it from PRIMARY to PS_Date ? Is it I have to re-create the particular table then only able to put in the partition scheme? Hope can get any assistance here. Thanks alot.



Best Regards,

Hans

View 8 Replies View Related

Better Practices Wanted For Cascading Inserts Of Hierarchical Data From Staging Tables

Aug 28, 2007

I apologize if this has been asked, but I can't find a complete answer.

We have a situation with parent/child tables which have an identity column as their PK. We need to be able to insert into the live tables from staging tables. The data in the staging tables are related via a surrogate key.

I have found the OUTPUT clause, but that can only refer to columns of the actual table (since there is no FROM clause in an INSERT). Our current best solution to this problem involves adding bogus "staging" columns to the destination tables, and removing them after we've inserted everything from staging. This is an unattractive solution to say the least.

I'll give an example that mirrors our actual solution, and ask if anyone has a better solution?
----------




Code Snippet
CREATE TABLE [dbo].[TABLE_A](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DATA] [nchar](10) NOT NULL,
[STAGING_COLUMN] [bigint] NULL,
CONSTRAINT [PK_TABLE_A] PRIMARY KEY ([ID] ASC)
)
GO
CREATE TABLE [dbo].[TABLE_B](
[ID] [int] IDENTITY(1,1) NOT NULL,
[A_ID] [int] NOT NULL,
[DATA] [nchar](10) NOT NULL,
[STAGING_COLUMN] [bigint] NULL,
CONSTRAINT [PK_TABLE_B] PRIMARY KEY ([ID] ASC)
)
GO
ALTER TABLE [dbo].[TABLE_B]
ADD CONSTRAINT [FK_TABLE_A_TABLE_B] FOREIGN KEY([A_ID]) REFERENCES [dbo].[TABLE_A] ([ID])
GO
CREATE TABLE [dbo].[STAGE_TABLE_A](
[A_Key] [bigint] NOT NULL,
[DATA] [nchar](10) NOT NULL
)
GO
CREATE TABLE [dbo].[STAGE_TABLE_B](
[B_Key] [bigint] NOT NULL,
[DATA] [nchar](10) NOT NULL,
[A_Key] [bigint] NOT NULL
)
GO


The STAGING_COLUMN columns are the ones that will be added before, and dropped after.






Code Snippet
DECLARE @TABLE_A_MAP TABLE (
A_ID INT,
A_Key BIGINT
)
INSERT INTO TABLE_A (DATA, STAGING_COLUMN)
OUTPUT INSERTED.ID, INSERTED.STAGING_COLUMN INTO @TABLE_A_MAP
SELECT DATA, A_Key FROM STAGE_TABLE_A
INSERT INTO TABLE_B (A_ID, DATA)
SELECT TAM.A_ID, STB.DATA
FROM STAGE_TABLE_B STB INNER JOIN @TABLE_A_MAP TAM ON TAM.A_Key = STB.A_Key






This seems to work, but I'd really like another alternative. Even though this is happening when nobody else is using the database, I cringe at the thought of adding and removing columns just to make this work.

Here are a few of my constraints:



The above is a simplification of the actual problem. The actual problem goes about five levels deep (hence the B_Key in STAGE_TABLE_B). At the top level, our larger customer will have 100,000 rows to insert. Each level will average 3 times as many rows as the next higher level, so we're talking about real volumes here.

This has to finish over the course of a weekend.

This has to be delivered to QA this Friday
Thanks for any help or insight.

View 3 Replies View Related

Accepted Practice To Query The Built-in Aspnet Membership Tables ?

Jul 17, 2007

I'm a relative newbie to ASP.NET development (web development in general) so please forgive the ignorance. ;-)
Ok, I'm using VWD to design and test my application and I'm using the standard membership provider system.  I've read in various places not to muck around with the aspnet_* tables as it can cause havoc hehe.  Therefore, I've created my own Member table to accommodate more fields that the aspnet_Users table does not have (since I don't want to mess around with that table) such as address, city, town, zip, birth date, etc.  Obviously, I have a field in Member that corresponds to the userId primary key in aspnet_Users.  Now, there are times when I need to display the username of a person's profile on a page.
SELECT aspnet_Users.UserName<br>FROM aspnet_Users, Member<br>WHERE querystringid=Member.memberId AND Member.userId = aspnet_Users.UserId
Now, this seems fine and dandy when there are few entries in the aspnet_Users table, but what if I tried that query when aspnet_Users grew to a hypothetical one million entries??  Does anyone know if those fields in aspnet_Users are properly indexed?  I can't seem to determine one way or another with VWD's database explorer.  I don't want to run the risk of a full table scan.  But if those fields aren't indexed, I don't know if I should modify that table in any way.
What to do?
TIA

View 4 Replies View Related

Limiting Tables Displayed In New Window For SQL 2000 Enterprise Manager

Jul 20, 2005

Can anyone tell me if there's a way to create new windows from thetables section of a database in Enterprise Manager such that I canlimit the tables included in that window? Ultimately, I'm looking fora solution whereby I can group tables, stored procedures, etc. intological groups that can then be displayed using different MMCconsoles. I'm looking for either a GUI-level or programatic approach.Thank you,Dax Westerman

View 1 Replies View Related

SQL Server 2008 :: Tables Not Shown In Articles Window Of New Publication Wizard

May 26, 2015

We have restored a database on new server without keeping replication settings. Now while creating the publication no tables are shown in new publication wizard window. In fact we have hundred of tables in database and included in replication on source server from where backup was taken.

What may be the reason that tables are not appearing?

View 1 Replies View Related

SQL Server 2012 :: Aggregation Table On Sliding Dates

Sep 18, 2014

currently need to re-create an aggregate table in a proc every night to aggregate purchases broken down by person/store in groups of 3, 6 12 etc months.finding the performance of it is very slow as it covers 500,000 million rows.The query looks like

SELECTCusID(int)
, StoreID(int)
, SUM(L3M) as Last3Months
, SUM(L6M) as Last6Months
, SUM(L9M) as Last9Months

[code]...

I need to make changes to this because it is using a BETWEEN on a datetime column. I was wondering though, if anyone else has made agg tables like this before an found a better way of doing them?

View 0 Replies View Related

TABLES AND INDEXES

Jun 7, 2001

How do I move a table (test1) to a physical file group, and the table(test1) indexes to another file group. One clustered index and 3 nonclustered indexes. Thanks!!!!

View 4 Replies View Related

Indexes On Tables

Oct 9, 2001

Hello List,

I've a customer table and It has two indexes only. But when I view from the query analyser it list ten indexes with the following name:

"_WA_Sys_status_01EAB64E"

I do not know, what does the above index does and i remember, I did not created that. When trying to drop that, It says, Its not an index. I dont know, what to do. Would somebody please advice me on this.

Thanks,

View 3 Replies View Related

Indexes On Tables

Mar 17, 2006

Hi,

Can someone point me to where I can find out if an SQL server table has an index ? I was in enterprise manager and brought up properties for any given table but was unable to find the information.

Thanks,
Jeff

View 7 Replies View Related

Decimal Point Shifting On SUM

Oct 27, 1998

The following SQL statement returns the correct totals except that
the total value is shifted on decimal place to the right. i.e. a real
total of 955.68 is displayed as 9,556.80. The total_ar field is a money type.
Any help would be appreciated.

Mark

/* AR report Total Greater than 365 days sorted by Dept */

select

a.dept as `Department `,
` A/R 365+ `=sum(case when datediff(day,c.bill_date, getdate()) > 365 then b.total_ar else 0 end)

from

hbm_persnl a, blt_billm b, blt_bill c,hbl_dept d,hbm_matter e

where
e.matter_uno = b.matter_uno and
a.empl_uno = e.bill_empl_uno and
b.bill_tran_uno = c.tran_uno and
b.ar_status = `O` and
e.status_code=`OPEN`

group by a.dept

View 1 Replies View Related

Data Shifting Between Records

Mar 23, 2008

Is there a problem with stability when one uses too many text (memo) fields?I'm having a problem with data from one record occasionally ending up inanother record, though apparently not through any user interaction.I'm using SQL 7 and accessing the tables through the ODBC driver. There aretwo tables with a one-to-one relationship -- TableA and TableB. TableB isthe one that's having this occasional problem. TableB has about 30 textfields out of a total of about 50 fields in the table. The problem isusually with one or two text fields containing data from a different record,one that was created close to when the problem record was created.Example: TableB has fields 1-9, say. In one record, field 1 has A, field 2as B, field 3 has C, and so on.In another record (created shortly after the other one), field 1 has AA,field 2 has BB, field 3 has CC, and so on.The user works with the records, everything's fine. Then one day the usernotices that in the second record, field 1 has AA, field 2 has BB, but field3 has C instead of CC. In other words, all data's fine, except for one,maybe two fields, that have data from a previously-created record.At first glance this seems to be a user-interaction thing, that somehow theuser inadvertantly placed data from the older record into the newer one,either through a shortcut, or by having that data on the clipboard, orwhatever. But a recent incident opposes that theory.I have two forms in the front end for editing records (the forms are boundto the ODBC table links). Form1 is bound only to TableA (the one thatdoesn't have the problem); Form2 is bound to a query that is TableA joinedwith TableB.In the recent incident where data shifted, both the record that was affectedand the record from which the data came were both only edited with Form1. Inother words, TableB never came into play; yet its data was somehow affected.When a record is created, the user completes a few fields in a form, andthen a stored procedure creates a record in TableA and then a sister recordin TableB (using the TableA record's autonumber primary key as its primarykey). A couple of user entered values are entered into the TableB record.But if the user is using Form1, they never see the TableB record.In this case, the TableB record's two fields got changed to fields from anearlier record (one which was created a little earlier the same day), eventhough both records were only edited in Form1 (according to the historylog), which doesn't touch TableB.Thus, I'm wondering if there's a possibility that either the SQL database orthe ODBC driver somehow shifted the data from one record into another. Thatseems far-fetched. But, at this point, since a table that the user didn'ttouch somehow had its data changed to data from a different record, I'mtrying to explore all possibilities.Thanks for any insight!Neil

View 4 Replies View Related

What Are The Biggest Tables And Indexes?

Apr 17, 2008

Is there any way to know which ones are the biggest (In Mb) tables and indexes in my database?

thanks

View 1 Replies View Related

Indexes On Related Tables...

Jun 17, 2007

Hi,

I have 2 tables with this design: one has ArticleID as primary key and multiple other fields and one has GroupID as primary key and multiple other fields. Each article can belong in multiple groups so I created a new table called articleGroups with only 2 fields: ArticleID and GroupID to show the groups associated with each article. There is a relation between this table and each of the main 2 tables. My question is, in the articleGroup table, does it make any sense to create an Index on ArticleID, GroupID or both? Since the group is needed for each article the Groups will always be queried everytime the article is queried. So, I am not sure if an index is needed?

Thank you,


Regards,

Iulian

View 5 Replies View Related

What Are The Biggest Tables And Indexes?

Apr 17, 2008

Is there any way to know which ones are the biggest (In Mb) tables and indexes in my database?

thanks

View 4 Replies View Related

Outer Join - Shifting Result Set.

Jul 23, 2005

I'm a quantitative securities analyst working with Compustat data(company fiscal reports and pricing feeds).My coworker came across a problem that we fixed, but I'd like tounderstand 'why' it was happening and just don't get it yet.Here's the starting query (reduced to simple prefixes):----INITIAL-----declare @mthDate datetimeset @mthDate = (select max(datadate) from t)declare @wkDate datetimeset @wkDate = (select max(datadate) from z)Select...fromzleft join a on a.idA = z.idA and a.idB = z.idBand a.datadate = z.datadateleft join b on b.idA = z.idA and b.idB = z.idBand b.datadate = @mthDateleft join c on c.idA = z.idA and c.idB = z.idBand c.datadate = @mthDateleft join d on d.idA = z.idA and d.idB = z.idBand d.datadate = z.datadateleft join e on e.idA = z.idAand e.datadate = @mthDateleft join f on f.idA = e.idA and f.datadate=e.date2left join g on g.idA = e.idA and g.datadate=e.date2left join h on h.idA = z.idAleft join k on k.ticker = z.tickerleft join m on m.idA = z.idA and m.idB=z.idBwherez.datadate = @wkDate<..some other expression filters...>and k.ticker is null----END INITIAL-----------As you can see 'z' is the main table that things are linked to viaouter joins (our security master). Table 'k' has a list of securitiesthat we wish not to have results for.There are 77 entries in table k and 4933 in table z for that giventime. We'd expect 4856 to be in this, but no. it's 4400, and then thenext time you run it (no changes whatsover) it's 2312, and so on.Every time you execute you get a different record count.My thought/and fix was to move the (k.ticker) predicate out of thewhere clause and get a differenced set from z using NOT EXISTS:-----AMENDED---------------from(z where not exists(select * from k where k.ticker=y.ticker)) yleft join a on a.idA = y.idA and a.idB = y.idBand a.datadate = y.datadateleft join b on b.idA = y.idA and b.idB = y.idBand b.datadate = @mthDateleft join c on c.idA = y.idA and c.idB = y.idBand c.datadate = @mthDateleft join d on d.idA = y.idA and d.idB = y.idBand d.datadate = y.datadateleft join e on e.idA = y.idAand e.datadate = @mthDateleft join f on f.idA = e.idA and f.datadate=e.date2left join g on g.idA = e.idA and g.datadate=e.date2left join h on h.idA = y.idAleft join k on k.ticker = y.tickerleft join m on m.idA = y.idA and m.idB=y.idBwherey.datadate = @wkDate<..some other expression filters...>------------------------And this works. It's stable now.I'm hoping someone here can help me up the wisdom curve by explainingto me 'why' the recordset kept changing before.My guess is that the cost-based optimizer was resorting the outer joinsand handing back different sets as a result, but i want to understand,and thought i'd come to this group for help.I appreciate your time and look forward to replies.Greg McIntire

View 7 Replies View Related

Shifting Past The Interim SQL2K

Apr 19, 2006

Hi all,

I've been working hard to drag my family and the family business into the modern life, took me long enough to get then off a 'coal-powered' Siemens Nixdorf miniframe. Anyway, they went for a package system, on a PC ntwork. Now I've been gradually migrating them again, teasing them (as sometimes you do) with the benefits that could be supplied by my software, written on an SQL 2k back-end.

So anyway, we now have a system that ties into FoxPro as its original system (the bought package), plus SQL 2K..... I'm now upgrading to SQL 2005, and Express for starters....

Is it going to be possible to easily to run queries against both SQL2k and FoxPro, or should I redo my current fix from 2k to 2005 and work from there... at the end of the day, it will all hopefully become a single system, as my new system takes over more and more of the other packages functionality. And on the flip side, if i remake my current SQL2k hook-in, am i going to hit problems when i remake/convert it to SQL Express (and yes, i know Express has limitations, but i need to persuade them to move before they'll pay up the cost of the full version)

Yours,

Ann-Marie

View 1 Replies View Related

How To List Tables,indexes,views Etc...

Jun 16, 2003

Hi,

I want to list the table names in a database "mydev_db".What would be the query ?.

I want to run a similar query to find out the indexes,views,stored_procs etc.



Regards,
Copernicus

View 3 Replies View Related

Changing Indexes In Replicated Tables

Dec 19, 2001

I need to drop and recreate indexes in some of my tables that are currently been replicated. I am not sure how this will affect my ongoing replication. Will this cause a problem for me? Please help

Bright

View 2 Replies View Related

How Much Space In A Db Is Available For Allocation To Tables And Indexes?

Nov 19, 2007

I was trying to find out how much space is available in a 2000 db for allocation to tables and indexes. I am trying to find the amount of space that has to be used-up before another allocation is automatically made to the database. I looked at sp_spaceused but BOL is rather sketchy at defining what the numbers it returns really mean. Is the "unallocated space" the value I am looking for?

Thanks,

Michael

View 1 Replies View Related

Should I Create Indexes On Views Or Tables

May 22, 2007

I have a pretty large database that has tables that will contain millions of rows of records. I will predominantly be using Views just to select the data. (I will not be performing any updates or inserts). I propose creating indexes on the views. My question is - if I create indexes on my views, do I have to create them on the tables as well? Is it good practice to create indexes on tables by default even if I am not going to be performing select statements directly on my tables but via my indexed views? Any advice is appreciated.

Thanks
Ran

View 4 Replies View Related

Alter Index For All Tables/indexes In A DB

Oct 22, 2007



In SQL Server 2000 one could DBReindex every index that exists in a given database. You can do the same in SQL Server 2005. But how can this be done with the new Alter Index command? It does not allow me to pass in a variable for the object. Any ideas on how to get this done in with Alter Index in 2005? Thanks!

This I can't get to work:

DECLARE
@TableName nvarchar(100)
SET @TableName = 'Account'

USE database;
GO
ALTER INDEX ALL ON @TableName
REBUILD
GO




USE RZTQ5OL02

DECLARE @TableName varchar(255)

DECLARE TableCursor CURSOR FOR

SELECT Name from sys.sysobjects where type = 'U'

OPEN TableCursor

FETCH NEXT FROM TableCursor INTO @TableName

WHILE @@FETCH_STATUS = 0

BEGIN

DBCC DBREINDEX(@TableName,' ',90)



FETCH NEXT FROM TableCursor INTO @TableName

END

CLOSE TableCursor

DEALLOCATE TableCursor

View 3 Replies View Related

Shifting To Server 2005 64bit Edition

Jul 11, 2007

Hi,

I have implemented a application on SQL Server 2005, this application runs huge queries and some stored procedures. Now that client is shifting on SQL Server 64bit edition, what should i need to worry about. What all changes am i expected to handle.

I would also like to know if there are any other issues to be considered.


Thank You.
STG Labs

View 6 Replies View Related

Creating A New Column By Shifting A Timestamp At Least 5 Seconds Later

Apr 8, 2008

I have a table that looks like this:

[Timestamp] [P]
2008-04-06 17:30:00 119
2008-04-06 17:30:03 120
2008-04-06 17:30:07 119
2008-04-06 17:30:11 118
2008-04-06 17:30:12 129
2008-04-06 17:30:13 125

What I'm after is to create a new [dtP] column where the [dtP] is the [P] value at least 5 seconds later. I would assume I should use the dateadd() function but I've tried [Timestamp] = dateadd(ss,5,[Timestamp]) in my WHERE clause and to no avail. Any suggestions on the best way to proceed?

Desired Result:

[Timestamp] [P] [dtP]
2008-04-06 17:30:00 119 120
2008-04-06 17:30:03 120 121
2008-04-06 17:30:07 121 122
2008-04-06 17:30:11 122 125
2008-04-06 17:30:12 128 125
2008-04-06 17:30:13 129 etc...
2008-04-06 17:30:14 125

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved