Error On Query To Sys Views (e.g. Sys.objects)
Mar 16, 2007
I've just installed SQL Server 2005 Developer Edition, upgraded from SQL Server 2000, and have encountered a problem in trying to query against the System Catalogs.
I've tried SELECT * FROM sys.objects in addition to SELECT suser_name( role_principal_id ) FROM sys.server_role_members. In both cases I receive the following error: Invalid object name 'sys.objects' or 'sys.server_role_members' in the second example.
I changed the properties of the registration for my local db instance to use SQL authentication in lieu of Windows authentication. I used the sa login account to see if that made a difference, no go.
Can someone *please* tell me what I'm doing wrong here?
I would also like to know if it's possible to run a query confirming the user account I'm logged in to the system as.
Thanks!
View 6 Replies
ADVERTISEMENT
Nov 20, 2006
I'm trying to copy data over using a Transfer SQL Server Objects Task however I get problems trying to copy over views. I get the similar error (pre sp1) when using import/export wizard and copying over views. Now with SP1 the views just don't transfer. I'm transferring from SQL 2005 to SQL 2005. The error I get is:
Error: 0xC002F363 at Transfer Data (NEW), Transfer SQL Server Objects Task: Table "vw_XXXX" does not exist at the source. Task failed: Transfer Data (NEW)
I know the view exists at the source because:
A) I can select it in the Views List Collection within the Transfer SQL Server Objects Task
B) I'm using the view on the source
Somehow the views are not transferring. Anyone have any ideas?
View 7 Replies
View Related
Apr 20, 2015
I am trying to replace object name in views , triggers, stored procs, UDF,TVF etc.I have created a automated script to replace 'dbo.Cust' with 'dbo.Customer' in all objects and generate script as ALTER Statements. some objects are still scripted out as Create. Reason is it has some extra space in between
CREATE TABLE #test1(
[NAME] [nvarchar](128) NOT NULL,
[DEFINITION] [nvarchar](max) NULL,
[DEFINITION_bk] [nvarchar](max) NULL,
[type] [char](2) NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
[code]....
View 5 Replies
View Related
Feb 25, 2008
Is there a way to give someone the right to create only views and no other objects in a database? Currently I have given the individual ddladmin database rose, but would rather be more restrictive?
View 1 Replies
View Related
Jun 22, 2007
Hi!
There is a view in our replicated SQL-2000 database, that returns all user tables and views with replication state (0 if not included into publication, 1 if included):
Code Snippet
CREATE VIEW [dbo].[ViewREPL_PublishedObjects]
AS
SELECT TOP 100 PERCENT
CASE [xtype]
WHEN 'U' THEN 'Table'
WHEN 'V' THEN 'View'
ELSE NULL END AS [Object Type],
[name] AS [Object Name],
CASE WHEN [replinfo] = 0
THEN 0 ELSE 1
END AS [Replicated]
FROM [sysobjects]
WHERE
[xtype] in ('U', 'V')
AND [status] > 0
ORDER BY
(CASE [xtype]
WHEN 'U' THEN 1
WHEN 'V' THEN 2
ELSE 10
END),
[name]
Now we need to upgrade our database to SQL-2005, but [sysobjects] table have been changed, so neither Replicated state could be determined according on [replinfo] column value, nor User/System object according on [status].
So, I need a view with same functionality, that will work under SQL-2005 and 2008.
Please, help!
View 2 Replies
View Related
Dec 27, 2006
please help newbieI need to create a lot of objects the same type (let's say: schemas)I wish to use paramerized block in loop to do so.- how to put names of my objects to such control-flow?belss you for help
View 5 Replies
View Related
Jan 4, 2005
I am getting the following error when executing a Copy SQL Server Objects Task. If it helps these objects are User Defined functions and also this had worked in the past it is only after changing the destination server to one that is offsite, has a different OS then the source and also runs as a DC. We are running SQL 2000 Server Standard with Spk 3a on both boxes.
Step 'DTSStep_DTSTransferObjectsTask_6' failed
Step Error Source: Microsoft SQL-DMO (ODBC SQLState: 42S02)
Step Error Description:[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.GetRightsAbbreviations'.
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.GetRights'.
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.GetTerritoryAbbreviations'.
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.GetTerritories'.
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.GetShow'.
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.GetTvEpisodes'.
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.GetTvSegments'.
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.GetTvSegmentsString'.
Step Error code: 800400D0
Step Error Help File:SQLDMO80.hlp
Step Error Help Context ID:1131
View 1 Replies
View Related
Feb 25, 2008
My website host allows me to create DB and DB users from its control panel and then I am able to use SQL server Management studio to Manage My DB.
Therefore I create My DB (TBC20) and create a user for it(Tony) from Host Panel.
When I want to Export My Local copy DB data to the remote DB using Import/Export wizard and set the It won’t Generate any DB objects. Even When I use aspnet_regsql Command I encounter Following error:
SQL error number is 262 and the SqlException message is: CREATE DATABASE permiss
ion denied in database 'master'.
Creating the TBC20 database...
------------------------------------------------------
When I View permissions in Database properties window No Permission is Grant for user: Tony. Only some permission Grant for Grantor: dbo. When I check Boxes to Grant Permission for user Tony None of permissions will be grant to this user.
How could I allow this user ti take ownership of DB and create DB objects
View 3 Replies
View Related
Mar 29, 2007
Hi all,
I'm trying to copy all tables (including indexes, triggers, etc) from one db to another using the transfer sql server object task.
I seem to able copy small amounts of tables (sometimes), but when I select ALL the tables, I get this handy error:
"The requested objects failed to transfer"
I had a few problems when trying to copy certain tables that had foreign keys, but that's sort of expected: you can't stick a key onto a table that references another table that doesn't exist!
I get this error when trying to copy a few tables that do have keys.
There are no primary or candidate keys in the referenced table 'Table1' that match the referencing column list in the foreign key 'FK_Table2_Table1'
Now, Table1 does have primary key on the source, but it seems to want to create the foreign key on Table_2 before the primary key on Table_1 has been created!
My Task is setup with the following:
IncludeExtendedProperties = True
DropObjectsFirst = False
CopySchema = True
IncludeDependentObjects = True
All the Table options (copy indexes etc) are set to True
I have SP2 installed
What am I doing wrong?
thanks
Michal
View 5 Replies
View Related
Jul 30, 2007
Hello,
I am sure there will be a simple answer to this but it has got me stumped.
Having to move over to Vista with my new machine so I am having to switch to 2005 version for my development but still upload to a 2000 server.
I have had a look at 2005, like the new Management Studio, however I ahve a couple of problems which I can not find the answer to.
Firstly, the SQL Query Builder, where has it gone? I often have to import/export data from Excel files and used to use the SQL query builder to create my queries. If I want to copy all columns it is fine but if I want to import select columns I find it easier to view a list and then just add the ones I want.
Am I missing something here?
Secondly, copying stored procedures, before when running DTS ther were three options, Copy Tables/Views, Data Using Query and Copy Objects.
I used the copy opbjects a lot as it was a very quick way of transfering a group of tables and stored prcoedures that I had created. This appears to have now been replaced with Copy Database, which copies everthing, can can not be used to copy from SQL2005 to SQL2000.
If I want to copy multiple stored procedures from SQL2005 to SQL2000 how is it done now? I have tried finding out but have not been sucessful.
Any help would be greatly appreciated,
Regards,
Lee
View 4 Replies
View Related
Jun 15, 2007
Hi ,
i am copying objects from one DB to other usign Transfer SQL Server Objects Task. i am getting this error
[Transfer SQL Server Objects Task] Error: Execution failed with the following error: "ERROR : errorCode=-1073548784 description=Executing the query "DROP TABLE [dbo].[testCopy] " failed with the following error: "Cannot drop the table 'dbo.testCopy', because it does not exist or you do not have permission.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.helpFile= helpContext=0 idofInterfaceWithError={8BDFE893-E9D8-4D23-9739-DA807BCDC2AC}".
it is true that object doesnt exist on the destination. but i want it to see if the object is there then drop otherwise just copy the object there,
Regards,
Haroon
View 1 Replies
View Related
Nov 20, 2013
passing serialised objects to a stored procedure for the purpose of data inserts. I see this as being a way to handle multiple row inserts efficiently.
However, in my limited use of XML data I am not so sure how to link the data when I have a dependency on another "object" within the serialised XML.
Below is a code snippet showing what I have so far.
The first insert statement works fine - but how to retrieve the identifier created by the DB - I want to use an SQL statement that finds the record in the table based on the XML representation (of the PluginInfo), allowing me to insert the ConfigurationInfo with the correct reference to the PluginInfo
DECLARE @Config NVARCHAR(MAX)
DECLARE @Handle AS INT
DECLARE @TransactionCount AS INT
SELECT @Config = '
<ConfigurationDirectory >
<ConfigurationInfo groupKey="Notifications" sectionKey="App.Customization.PluginInfo"
[code]....
View 1 Replies
View Related
Nov 4, 1999
I'd like to write a query that lists all the views for a particular database, can anyone help me out with this?
I've played around with the information_schema.views that the online books references, but I can't get it to return a list of the views? I know I can just
look at the views through enterprise manager, but I need to do this through a query. Many thanks
View 2 Replies
View Related
Apr 3, 2006
Fellow database developers,I would like to draw on your experience with views. I have a databasethat includes many views. Sometimes, views contains other views, andthose views in turn may contain views. In fact, I have some views inmy database that are a product of nested views of up to 6 levels deep!The reason we did this was.1. Object-oriented in nature. Makes it easy to work with them.2. Changing an underlying view (adding new fields, removing etc),automatically the higher up views inherit this new information. Thismake maintenance very easy.3. These nested views are only ever used for the reporting side of ourapplication, not for the day-to-day database use by the application.We use Crystal Reports and Crystal is smart enough (can't believe Ijust said that about Crystal) to only pull back the fields that arebeing accessed by the report. In other words, Crystal will issue aSelect field1, field2, field3 from ReportingView Where .... eventhough "ReportingView" contains a long list of fields.Problems I can see.1. Parent views generally use "Select * From childview". This meansthat we have to execute a "sp_refreshview" command against all viewswhenever child views are altered.2. Parent views return a lot of information that isn't necessarilyused.3. Makes it harder to track down exactly where the information iscoming from. You have to drill right through to the child view to seethe raw table joins etc.Does anyone have any comments on this database design? I would love tohear your opinions and tales from the trenches.Best regards,Rod.
View 15 Replies
View Related
Mar 17, 2015
If I skip those objects that were deleted, is there a query that I can run off Master/MSDB that will show all database objects and when they were last modified, or create date if it has not been modified?
View 7 Replies
View Related
Feb 20, 2008
Sorry seem to be havign no end of trouble with SQL today. I need to create a query that will rank tickets using the row count of another table which has a relationship with the primarykey of that ticket table. I decided to spilt it into two querys, one which gets the count each ticketid has within a date peroid and relating to a os:: SELECT COUNT(*) AS count, Tickets.TicketID, Systems.OSFROM Rating INNER JOIN Tickets ON Rating.TicketID = Tickets.TicketID INNER JOIN Systems ON Tickets.SystemID = Systems.SystemIDWHERE (Rating.DateVoted >= @date)GROUP BY Tickets.TicketID, Systems.OSHAVING (Systems.OS = @osid) This works, BUT when I put in the date using: command.CommandText = "SELECT COUNT(*) AS count, Tickets.TicketID, Systems.OS FROM Rating INNER JOIN Tickets ON Rating.TicketID = Tickets.TicketID INNER JOIN Systems ON Tickets.SystemID = Systems.SystemID WHERE (Rating.DateVoted >=" + Datetime.Now.Adddays(-7) + ") GROUP BY Tickets.TicketID, Systems.OS HAVING (Systems.OS =" + 1 + ")"; And it throws up an error saying there was a syntax error at '22' (the hour I am currently on). So: Any idea how I can fix thisAny ideas on creating a query that will do the above, but also return the ticket informationHow do you link querys (I might have to do this if I can't work out 2)Please, If anyone has any ideas. This is driving me crazy
View 5 Replies
View Related
Jan 23, 2007
https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=127100
I don't believe that the fix to the above issue has made its way into an SP yet. Can anyone confirm/refute this, and/or state when the fix will become publicly available &/or give a workaround?
Thanks,
Tamim.
View 3 Replies
View Related
Sep 5, 2007
Does anyone know how to count rows of data from 1 table that meet one or two different criteria and then get the probability of occurance for that criteria ... as an output column?
Do I use 'Having' or temp tables or Views?
Here is my output for now. I am trying to solve for 'Prob' - everything else works on it's own.Craig
SELECT Wins_Lng/Trades_Lng as Prob
FROM Transactions
SELECT Count(Ticker) as Trades_Lng
FROM Transactions
WHERE TransType='C' AND DateDiff(day,BaseDate,GetDate())<=100 AND TransKind='B' (SELECT COUNT(Ticker)as Wins_Lng
FROM TransactionsWHERE Transkind='B' AND TransType='C' AND DateDiff(day,BaseDate,GetDate())<=100 AND Profit_Lng>=0)
View 2 Replies
View Related
Apr 28, 2008
I have a table which records the amount of times a user views a webpage
tblpageview
id
pagename
view_date
userid
I would like to have a query that returns the unique pagename and the amount of times that page has been viewed. I've had a go with count etc. but cant seem to get it. Anyone can help?
View 3 Replies
View Related
Apr 25, 2006
Here's the setup:
Client database has a complex view with eight nested subqueries used to return "dashboard" information. The application code uses NHibernate to call and filter the view with three parameters, one of which is the CustomerID.
A certain customer, (the biggest client), has more than ten times the number of records of the next largest customer.
Occasionally, the database reaches a state where when this particular customer tries to run the dashboard view, the application times out.
If I open up the view and re-save it, all is well again for a few days.
What gives?
Views are supposedly not pre-compiled, though I know that 2000 stores bits and pieces of query plans.
Any ideas on what causes this and what to do about it?
View 2 Replies
View Related
Jul 16, 2014
In SQL server 2008 how can I run the same query against each view in that database?
One database about 75 views.
Or even something like
Select 'yes' from view
Where shipping_status = 'delayed'
And return a list of view names so I know which views to query against.
I ran
Code:
select name from sysobjects where type = v
And got a list of my views. How can I now run my SQL statement against the list to see which views contain the info?
View 1 Replies
View Related
Jan 17, 2008
We know that a query execution plan exists for Stored Procedures in the Procedure Cache.
What about Views? Does a view have a query execution plan? We know that a View is a virtual table and that virtual table is populated
when the view is induced but does it have a Query Execution Plan?
I have tried to find this info for Views in BOL but I cannot see it anywher in BOL.
View 9 Replies
View Related
Mar 3, 2004
Dear Team,
Can any body tell in which table the stored procedure error
details are stored.
When any stored procedure is compiled the
compilation errors/results are stored in which table.
i.e equivalent to user_errors as in Oracle.
Any help will be greatly appreciated.
Regards,
Sridhar
View 2 Replies
View Related
Oct 23, 2006
Ok, What I want to achieve is plain stuff, I want to join 2 views on a common key.It all works well with the SQL2000 Query Analyzer, but not trough ADO.NET or should I say my webapplication.With that I mean that my query return rows when executed from SQL2000 Query Analyzer, But not when used in my application or Executed from the Visual Studio Server Explorer.I have struggled with this one for several hours, I cant get this one right.So lets bring in the one who actually know what his doing View1: 1 select
2 cast((PS.RabattProsent/100.00)*PS.Pris AS decimal(11,2)) AS Rabatt
3 ,cast((PS.MVAProsent/100.00)*PS.Pris AS decimal(11,2)) AS MVA
4 ,cast(PS.Antall * ((PS.Pris*(100-PS.RabattProsent))/100)*((PS.MvaProsent/100.00)+1) AS decimal(11,2)) AS Belop
5 ,PS.*
6 ,K.Kunde_ID
7 FROM
8 tbl_ProduktSalg AS PS
9 INNER JOIN
10 tbl_Ordre AS O
11 ON
12 O.Ordre_ID = PS.Ordre_ID
13 INNER JOIN
14 tbl_Kunde AS K
15 ON
16 K.Kunde_ID = O.Kunde_IDView2: 1 SELECT
2 PS.Ordre_ID
3 ,SUM(cast((PS.RabattProsent/100.00)*PS.Pris AS decimal(11,2))) AS TotalRabatt
4 ,SUM(cast(PS.Antall * ((PS.Pris*(100-PS.RabattProsent))/100)*((PS.MvaProsent/100.00)+1) AS decimal(11,2))) AS TotalBelop
5 ,SUM(PS.Pris) AS TotalPris
6 ,SUM(cast((PS.MVAProsent/100.00)*PS.Pris AS decimal(11,2))) AS TotalMVA
7 FROM
8 tbl_ProduktSalg AS PS
9 GROUP BY
10 PS.Ordre_ID
MyQuery/SPRC: 1 create procedure %PROC% (@Kunde_ID int, @Ordre_ID int)
2 as
3 begin
4 SELECT
5 v_PSD.*
6 ,v_OTS.TotalRabatt
7 ,v_OTS.TotalBelop
8 ,v_OTS.TotalPris
9 ,v_OTS.TotalMVA
10 FROM
11 v_ProduktSalgDetaljer AS v_PSD
12 INNER JOIN
13 v_OrdreTotalSum AS v_OTS
14 ON
15 v_OTS.Ordre_ID = v_PSD.Ordre_ID
16 WHERE
17 v_PSD.Kunde_ID = @Kunde_ID
18 AND
19 v_PSD.Ordre_ID = @Ordre_ID
20
21 end
22
View 3 Replies
View Related
Oct 22, 2004
When working with databases containing myriad of huge tables, I am very much tempted to create categorized views on those tables in order to simplify and facilitate data query programming? Some developers I talk to say such views generally slow down query performance. Is this true?
Thanks.
View 1 Replies
View Related
May 1, 2006
Over the years I've read and experienced where joining more then 5 tables can lead to performance problems. This number can vary based upon the amount of data in each table, if and how indexes are used and the complexity of the query, but 5 has always been a good rule of thumb. Unfortunately I do not know what rule to apply in regards to joing views.
A developer has experienced timeout problems periodically when opening a view in EM or when running the code which makes-up the view. I decided to look at the view and noticed it references tables and views, which reference more views, which in turn reference other views. In all the initial view references 5 tables and 8 views directly and indirectly, with some of the views containing function calls. What are your thoughts on how many views and tables are too many when it comes to joins and query performance.
Thanks, Dave
View 6 Replies
View Related
Oct 17, 2001
I have an indexed view with a clustered index on my database........when I try to run and update statement agaisnt the table that is referenced in the view, I get one of the following errors:
Server: Msg 3624, Level 20, State 1, Line 1
Location: q:SPHINXNTDBMSstorengdrsinclude
ecord.inl:1447
Expression: m_SizeRec > 0 && m_SizeRec <= MAXDATAROW
SPID: 52
Process ID: 414
Connection Broken
Server: Msg 3624, Level 20, State 1, Line 1
Location: recbase.cpp:1371
Expression: m_nVars > 0
SPID: 52
Process ID: 414
Connection Broken
any ideas?
View 2 Replies
View Related
Apr 17, 2007
we are trying to replicate a database from 1 server to another, but during the snapshot, the process will fail with the following error.
The process could not bulk copy out of table '[dbo].[syncobj_0x4645324137444535]'.
i located this table....or actually 'View'....and im trying to determine whether this view is actually needed or not....
any help would be greatly appreciated
View 1 Replies
View Related
Sep 13, 2007
I would like to do this for materialized view
insert value '00466045730060107' through View c. it will insert into table a.
But i got this error when i try to insert into view "C"
Msg 4436, Level 16, State 12, Line 3
UNION ALL view 'X.dbo.c' is not updatable because a partitioning column was not found.
insert into c
values('00466045730060107')
--------------------------------------------------------------------------------------------------
CREATE TABLE a
(
chara char(17)
CONSTRAINT PKA PRIMARY KEY CLUSTERED
CHECK (right(inta,6) between '060101' and '060131' )
)
CREATE TABLE b
(
chara char(17)
CONSTRAINT PKb PRIMARY KEY CLUSTERED
CHECK (right(inta,6) between '060201' and '060228' )
)
create view c
as(
select inta from a
union all
select inta from b
)
-----------------------------------------------------------------------------------------
View 2 Replies
View Related
May 15, 2006
Hi all,
I executed the following code statements in my SQL Server Management Studio Express Edition program that is on Windows XP Pro PC-Microsoft Windows NT 4 LAN system:
-----SQLQuery.sql-------
USE testDb
GO
CREATE VIEW InventoryPublisherView AS
(SELECT * FROM Inventory AS I FULL OUTER JOIN Publisher AS P ON I.ID=P.InventoryID
SELECT * from InventoryPublisherView
SELECT Name, type, quantity, pubName from InventoryPublisherView
DELETE FROM InventoryPublisherView WHERE ID=1
ALTER VIEW InventoryPublisherView AS
(SELECT ID,name,type,quantity,pubName FROM Inventory AS I FULL OUTER JOIN Publisher AS P ON I.ID=P.InventoryID)
GO
///////////////////////////////////////////////////////////////////////////////////
I got the following error messages in Parse or Execute without Results:
Msg 156, Level 15, State 1, Procedure InventoryPublisherView, Line 3
Incorrect syntax near the keyword 'SELECT'.
Msg 111, Level 15, State 1, Procedure InventoryPublisherView, Line 6
'ALTER VIEW' must be the first statement in a query batch.
************************************************************
I have no ideas where in the SSMS-EE program I can look up for solving theses errors.
Please help tell me where I should look up and advise me what I should do to correct these problems.
Thanks in advance,
Scott Chang
View 6 Replies
View Related
Sep 23, 2007
Hello,
I am running a package that used to transfers data from one SQL2005 to another SQL2005. There are multiple schemas associated with the database. Until recently, this pacakage would work. Now I am getting the following error for all the tables not owned by dbo:
Any help on this would be appreciated.
Thanks, sck10
[Transfer SQL Server Objects Task] Error: Table "tblAudiocast" does not exist at the source.
Microsoft SQL Server Management Studio 9.00.3042.00
Microsoft Analysis Services Client Tools 2005.090.3042.00
Microsoft Data Access Components (MDAC) 2000.085.1117.00 (xpsp_sp2_rtm.040803-2158)
Microsoft MSXML 2.6 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 7.0.5730.11
Microsoft .NET Framework 2.0.50727.832
Operating System 5.1.2600
View 5 Replies
View Related
Feb 22, 2007
Yes, I do know what this means and why the error is thrown but this is not my question.
I have two servers that are both running Windows Server 2003 and SQL Server 200 SP3. Below are the results from both servers using @@version
Sever 1 (BB)
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
Server 2 (Genesis)
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
These servers are identical or so it seems. I've got a real ugly query that uses views and a derived table to get results. The problem is the 256 limit message only comes up on one server and on the other (Genesis) the query runs fine. I get the error though it reads a 260 limit on a box with SP4 applied. I've also run the query on a box that is Windows 2003, sql2k and sp4 and the query runs but not on a similar server here. This is all very odd. Please note that the database structure, views, etc are all exactly the same as far as I know.
Any suggestions? There seems to be no pattern between versions of Windows and/or SP levels.
View 1 Replies
View Related
Mar 21, 2007
Hi,
I have come across this problem with SQL server both on 2000 and 2005. I am stating an example here.
I have two partitioned tables and a view on top of both tables as below:
create table [dbo].[Table_1]
(
[TableID] INTEGER PRIMARY KEY NONCLUSTERED
CHECK NOT FOR REPLICATION ([TableID] BETWEEN 1 AND 999),
[AnyOtherColumn] int NOT NULL ,
) ON [Primary]
GO
create table [dbo].[Table_2]
(
[TableID] INTEGER PRIMARY KEY NONCLUSTERED
CHECK NOT FOR REPLICATION ([TableID] BETWEEN 1000 AND 1999),
[AnyOtherColumn] int NOT NULL ,
) ON [Primary]
GO
create view TableView
as
select * from Table_1
union all
select * from Table_2
GO
Note the NOT FOR REPLICATION clause on the check constraint on the TableID column.
I then ran the query execution plan for the following query on both SQL server 2000 and 2005.
select * from TableView where TableID = 10
On both the versions the execution plan shows and Index seek on both the tables in the view. This means that my partitioning is not working. If I remove the primary key constraint from the TableID column, the same query on the view shows a table scan on all the underlying tables. This is even worse.
Next, create the same tables and views again, now without the NOT FOR REPLICATION clause on the check constraint as show below:
create table [dbo].[Table_1]
(
[TableID] INTEGER PRIMARY KEY NONCLUSTERED
CHECK ([TableID] BETWEEN 1 AND 999),
[AnyOtherColumn] int NOT NULL ,
) ON [Primary]
GO
create table [dbo].[Table_2]
(
[TableID] INTEGER PRIMARY KEY NONCLUSTERED
CHECK ([TableID] BETWEEN 1000 AND 1999),
[AnyOtherColumn] int NOT NULL ,
) ON [Primary]
GO
create view TableView
as
select * from Table_1
union all
select * from Table_2
GO
Now run the query execution plan for the same query again.
select * from TableView where TableID = 10
This time you would see that it does an index scan only on the first parititon table. This time it proves that the partitioning works.
I would like to know why does the NOT FOR REPLICATION clause in the check constraint make such a huge difference?
Is it a bug in SQL server?
Or am I missing any thing?
Any help appreciated.
Thanks
View 2 Replies
View Related