|
|
|
SSCertifiable
       
Group: Moderators
Last Login: Thursday, May 09, 2013 12:38 PM
Points: 6,462,
Visits: 1,384
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 6:12 AM
Points: 2,526,
Visits: 3,620
|
|
Hi Andy!
Thanks for this nice quickie! What I really like about this one is its simplicity and shortness. It doesn't always have to be the complete and in-depth analysis of a technology. The latter often scares people away because they think it is too complex and not worth investing all this time (definitively speaking about me here . But getting results within a few moments removes this obstacle in my mind.
Of course after the quick feedback I recommend every user to dive deeper into the details once the decision was made to utilize the specific technology.
Best Regards,
Chris Büttner
|
|
|
|
|
SSCertifiable
       
Group: Moderators
Last Login: Thursday, May 09, 2013 12:38 PM
Points: 6,462,
Visits: 1,384
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, August 22, 2008 1:08 PM
Points: 9,
Visits: 24
|
|
Thanks for the article - I have been wanting to learn more about partitioning, and your explanations are so clear! In my case, I am dealing with a data warehouse and tables that have tens of millions of rows, updated daily of course. Is there a way to tweak your method so I don't have to recreate the partitioned tables daily?
|
|
|
|
|
SSCertifiable
       
Group: Moderators
Last Login: Thursday, May 09, 2013 12:38 PM
Points: 6,462,
Visits: 1,384
|
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, September 18, 2012 9:04 PM
Points: 306,
Visits: 70
|
|
--Sql Server 2000
create table t1 (sno int, dob smalldatetime,name char(10)) create table t2 (sno int, dob smalldatetime,name char(10))
insert into t1 select 1,'01-01-2006','a' insert into t1 select 2,'01-07-2006','b'
insert into t2 select 3,'01-01-2007','c' insert into t2 select 4,'01-07-2007','d'
create clustered index cdxt1 on t1(sno) create clustered index cdxt2 on t2(sno)
create view T12 as select * from dbo.t1 union select * from dbo.t2
select * from t12 where dob>='01-01-2007'
--alter table t1 drop constraint ckt1 --alter table t2 drop constraint ckt2
alter table dbo.t1 with check add constraint CKt1 check ([dob] < '01-01-2007' ) alter table dbo.t2 with check add constraint CKt2 check ([dob] >= '01-01-2007' )
Need help on how to create constraint on t1 and t2 for smalldatetime columns??? as select * from t12 where dob>='01-01-2007' scanning both tables
Kindest Regards,
Tahir
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 6:12 AM
Points: 2,526,
Visits: 3,620
|
|
Hello Tahir,
two points: 1. Use UNION ALL instead of UNION. Since you have distinct rows in both tables you don't need to remove duplicates.
2. Cast or convert the date string to a smalldatetime: SELECT * FROM t12 WHERE dob>=CAST('20070101' AS smalldatetime)
Best Regards,
Chris Büttner
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 8:03 AM
Points: 264,
Visits: 181
|
|
Hi Andy
Thanks for this info and I can see how it works when running the query
select * from dbo.Contact where lastname = 'green'
However when trying the following, it reverts to looking at both underlying tables again
DECLARE @lastname VARCHAR(10) SET @lastname = 'green'
select * from dbo.Contact where lastname = @lastname
Is there any way this can only look at the one table? Or would I have to write my stored procedures using dynamic sql to take advantage of this?
|
|
|
|