Updating A Partitioned View In A Cursor
I have a partitioned view defined by a UNTION ALL of member tables. I can update the member tables through the view without any problem. However, when I declare a cursor on this partitioned view and try to update the view using WHERE CURRENT OF, I get an error saying 'The target object type is not updatable through a cursor'. Does anyone know if it's the case that updating a partitioned view through cursor is not supported in SQL Server 2000?
Thanks
View Complete Forum Thread with Replies
Related Forum Messages:
SQL 2000 Partitioned View Works Fine, But CURSOR With FOR UPDATE Fails To Declare
This one has me stumped. I created an updateable partioned view of a very large table. Now I get an error when I attempt to declare a CURSOR that SELECTs from the view, and a FOR UPDATE argument is in the declaration. There error generated is: Server: Msg 16957, Level 16, State 4, Line 3 FOR UPDATE cannot be specified on a READ ONLY cursor Here is the cursor declaration: declare some_cursor CURSOR for select * from part_view FOR UPDATE Any ideas, guys? Thanks in advance for knocking your head against this one. PS: Since I tested the updateability of the view there are no issues with primary keys, uniqueness, or indexes missing. Also, unfortunately, the dreaded cursor is requried, so set based alternatives are not an option - it's from within Peoplesoft.
View Replies !
Help With Partitioned Views Or Updating Data From Multiple Tables
Hi All, My database's design is set out here. In summary, I'm trying to model a Stock Exchange for a Technical Analysis application written using Visual C++. In order to create the hierachy I'm using a Nested Set Model. I'm now trying to write code to add and delete equities (or, more generically, nodes) to the database using a form presented to the user in my application. I have example SQL code to create the necessary add and delete procedures that calculate the changes to the values in the lft and rgt columns, but these examples focus around a single table, where as my design aggregates rows from multiple tables using UNION ALL: Code Snippet CREATE VIEW vw_NSM_DBHierarchy -- Nested Set Model Database Hierarchy AS SELECT clmStockExchange, clmLeft, clmRight FROM tblStockExchange_ UNION ALL SELECT clmMarkets, clmLeft, clmRight FROM tblMarkets_ UNION ALL SELECT clmSectors, clmLeft, clmRight FROM tblSectors_ UNION ALL SELECT clmEPIC, clmLeft, clmRight FROM tblEquities_ Essentially, I'm trying to create an updateable view but I receive the error "UNION ALL View is not updatable because a partitioning column was not found". I suspect that my design in wrong or lacks and this problem is highlighting the design flaws so any suggestions would be greatly appreciated.
View Replies !
Partitioned View
Hi! This is my first post and I really need help with Partitioned View. I'm using Sql Server 2000 and I created a partitioned view using 6 tables and now a need to create the table '7' and alter the view. But when i'm trying to insert new data i'm receiving the message: :eek: "Server: Msg 4416, Level 16, State 5, Line 1 UNION ALL view 'tb_sld_cob_pap' is not updatable because the definition contains a disallowed construct." My code is: drop VIEW tb_sld_cob_pap GO CREATE TABLE dbo.tb_sld_cob_pap_7 ( cod_operacao int NOT NULL , cod_contrato int NOT NULL , sequencial_duplicata int NOT NULL , data_sld_pap smalldatetime NOT NULL CHECK ([data_sld_pap] >= '20060201'), liqex_dia_nom_outros float NULL , liqex_dia_moe_outros float NULL, constraint pk_pap7 primary key (cod_operacao,cod_contrato,sequencial_duplicata,da ta_sld_pap) ) GO CREATE INDEX IdxSldCobPap7_1 ON dbo.tb_sld_cob_pap_7(cod_titulo, seq_titulo, data_sld_pap) GO CREATE INDEX IdxSldCobPap7_2 ON dbo.tb_sld_cob_pap_7(cod_operacao, seq_ctr_sacado, sequencial_duplicata, data_sld_pap) GO ALTER TABLE dbo.tb_sld_cob_pap_6 DROP CONSTRAINT CK__tb_sld_co__data___6C190EBB GO ALTER TABLE dbo.tb_sld_cob_pap_6 ADD CONSTRAINT CK__tb_sld_co__data___6C190EBB CHECK (((([data_sld_pap] >= '20051201') and ([data_sld_pap] < '20060201')))) GO create VIEW tb_sld_cob_pap as select * from tb_sld_cob_pap_1 union all select * from tb_sld_cob_pap_2 union all select * from tb_sld_cob_pap_3 union all select * from tb_sld_cob_pap_4 union all select * from tb_sld_cob_pap_5 union all select * from tb_sld_cob_pap_6 union all select * from tb_sld_cob_pap_7 My table tb_sld_cob_pap_6 does NOT have data with ([data_sld_pap] >= '20060201'). I'm using this script in other database and I don't have this problem. Thank you...
View Replies !
Partitioned View
USE Northwind GO CREATE TABLE myTable99_1 ( Accountchar(3) , Ledgerchar(4) , PostDatedatetime , PRIMARY KEY (Account, Ledger) , CHECK(PostDate> '1/1/1999' and PostDate < '12/31/1999 23:59:59')) CREATE TABLE myTable99_2 ( Accountchar(3) , Ledgerchar(4) , PostDatedatetime , PRIMARY KEY (Account, Ledger) , CHECK(PostDate> '1/1/2000' and PostDate < '12/31/2000 23:59:59')) CREATE TABLE myTable99_3 ( Accountchar(3) , Ledgerchar(4) , PostDatedatetime , PRIMARY KEY (Account, Ledger) , CHECK(PostDate> '1/1/2001' and PostDate < '12/31/2001 23:59:59')) CREATE INDEX myTable99_1_IX ON MyTable99_1 (Account, Ledger) CREATE INDEX myTable99_2_IX ON MyTable99_2 (Account, Ledger) CREATE INDEX myTable99_3_IX ON MyTable99_3 (Account, Ledger) GO CREATE VIEW myView99 AS SELECT Account , Ledger , PostDate FROM myTable99_1 UNION ALL SELECT Account , Ledger , PostDate FROM myTable99_2 UNION ALL SELECT Account , Ledger , PostDate FROM myTable99_3 GO SELECT * FROM myView99 WHERE Account = 1 AND Ledger = 1 GO DROP VIEW myView99 DROP TABLE myTable99_1, myTable99_2, myTable99_3 GO OK, so I thought I knew this, but I'm looking for parallelism...not only am I no getting it, I'm getting an Index scan....is it becuse I didn't put any data in the table? I thought it would stil show my index seek with parallelism What up, homey?
View Replies !
Partitioned View
I have a big table with about 40 million rows. Questions I have are: 1. Do I need to split this table into several small tables and then create a partitioned view or would one big table good enough for performance? 2. If I create a partitioned view then does that mean I have to continually adding tables to this view since there will be new records that need to be added? Is there a way to automatically create new tables to be added to the partitioned view?
View Replies !
Partitioned View On SS2000
There has been a functional change under SS2000 such that a partitioned view needs to be partitioned on a primary key. Under SS7 we had the data logically divided into separate tables based on an identifier. As a single table this is over 70Gb, but this breaks down into 18 individual tables within a view. The performance under SS7 was very good as the query would only look at relevant tables, but SS2000 now looks at all the tables in the view. There is an example of the problem below and I would very much appreciate any constructive contributions towards finding a resolution to this. Create table table1 (f1 char(10), f2 int) Create table table2 (f1 char(10), f2 int) GO Alter table table1 with check add constraint chk_table1_f2 check (f2 = 1) Alter table table2 with check add constraint chk_table2_f2 check (f2 = 2) GO insert into table1 values ('aaa',1) insert into table1 values ('bbb',1) insert into table1 values ('ccc',1) insert into table2 values ('xxx',2) insert into table2 values ('yyy',2) insert into table2 values ('zzz',2) GO create view tableview as select * from table1 union all select * from table2 GO -- the execution plan under SS7 shows that only table1 will be scanned -- for the following query, whereas under SS2000, both tables are -- scanned. select * from tableview where f2=1
View Replies !
More Than One Column In Partitioned View??
Hello.. Im having trouble to make a partitioned view when I use more than one column in check constraint! Should I use check constraint on all the primary keys? or is't possible to have 5 primary and check constraints on 2 of them ? I've read Creating a partitioned view (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_06_17zr.asp?frame=true) But i cannot see limitations on this???
View Replies !
Partitioned View Misbehaving!
Hi all, I have a partitioned view on SQL Server 2000 containing 4 tables (example below) The query plan generated on a select correctly accesses just one of the tables The query plan generated on an update always accesses all four of the tables. I thought that it should only access the partition required to satisfy the update. Can anyone please advise whether: a) Is this is expected behaviour? b) Is the partitioned view incorrectly configured in some way? c) Is there is a known bug in this area? Note that the behaviour is the same with SP1 on SQL2000 Example follows --Create the tables and insert the values CREATE TABLE Sales_West ( Ordernum INT, total money, region char(5) check (region = 'West'), primary key (Ordernum, region) ) CREATE TABLE Sales_North ( Ordernum INT, total money, region char(5) check (region = 'North'), primary key (Ordernum,region) ) CREATE TABLE Sales_East ( Ordernum INT, total money, region char(5) check (region = 'East'), primary key (Ordernum,region) ) CREATE TABLE Sales_South ( Ordernum INT, total money, region char(5) check (region = 'South'), primary key (Ordernum,region) ) GO INSERT Sales_West VALUES (16544, 2465, 'West') INSERT Sales_West VALUES (32123, 4309, 'West') INSERT Sales_North VALUES (16544, 3229, 'North') INSERT Sales_North VALUES (26544, 4000, 'North') INSERT Sales_East VALUES ( 22222, 43332, 'East') INSERT Sales_East VALUES ( 77777, 10301, 'East') INSERT Sales_South VALUES (23456, 4320, 'South') INSERT Sales_South VALUES (16544, 9999, 'South') GO --create the view that combines all sales tables CREATE VIEW Sales_National AS SELECT * FROM Sales_West UNION ALL SELECT * FROM Sales_North UNION ALL SELECT * FROM Sales_East UNION ALL SELECT * FROM Sales_South GO --Look at execution plan for this query -- This correctly only accesses the South partition SELECT * FROM sales_national WHERE region = 'south' -- Look at execution plan for update -- This accesses all partitions - Why - it includes the partition key? update sales_national set total = 100 where ordernum = 23456 and region = 'South'; I would be very grateful for any advice Thanks Jaishel.
View Replies !
Partitioned View Problem
Hi all, I am designing 3 p:artitioned views for 3 tables. Those tables grow up in 1.5 millions of rows per month (each one), so I decided to partition those tables monthly. The issue is that if I want to create the views with more than 256 months (256 tables) SQL Server says: 'Server: Msg 106, Level 15, State 1, Procedure Jugadas, Line 258Too many table names in the query. The maximum allowable is 256.' Is there any workaround for this? Another solution maybe? PD1: I've tested with less than 256 tables and it works fine, I can update and query the tables (except for a couple of querys where I've got to join 2 or more of the involucred views in which case I got a similar error saying about a 260 table limit).
View Replies !
Partitioned View Question
I have a table that I'm trying to scale out into a partitioned view. It's about 30 million rows. It's a workflow table and I have a taskID in the table. Originally the table was partitioned on this column but performance still wasn't what I wanted it to be, so we figured out how we could partition on a bit flag of IsOpen. Question #1) Anyone know a best practice for creating apartitioned views on multi-columns? What I'd like to try to do to lower the complexity of the original partitioned view is to create a view of partitioned views. Is this even possible (This is Q#2, BTW).
View Replies !
Will This Query Be Optimized For A Partitioned View?
Hello :-)My question is: If I query a partitioned view, but don't know the valuesin the "where x in(<expression>)" clause, i.e.: select * from viewAwhere intVal in(select intVal from tbl1) . Compared to: select * fromviewA where intVal in(5,6).Of course "intVal" is partitioning column.Will this result in an optimized query that searches only the relevanttables?*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
View Replies !
Partitioned View Performance Question
I'm fairly new to partitioned views, but am implementing one in test to see if it would be a worthy candidate for production. The test server is basically a workstation with 2 drives, one for data, one for logs. There is a fairly large table (87M rows) and a partitioned view written against multiple tables with columns matching those in the 87M row table. To mirror a typical day in production, I needed to insert about 2.5M rows into each (the big table, and the view). However, when doing so, I didn't get the performance increase I'd expected. Inserting the 2.5M records into the 87M row table took approximately 6.5 minutes. The insert into the view took approximately 2 hours and 52 minutes. This seems absurd. The data added is heavily based on one particular date (ie; most of the data will be for one date, with maybe 1% of the data being of other dates). The tables behind the view are broken up by date. So, most of the data would have went into one table, with a small percentage going into other tables. Default Fill Factors were used, no out of the ordinary tuning done anywhere. There's an index on the date field in the 87M row table, but that's about it. I'm confused, any ideas?
View Replies !
Bulk Insert In To A Partitioned View?
Greetings once again my SQL friends, I am getting the following error when I attempt to complete my data flow task. The destination is a partitioned view but I get the following error message when I run the package : Partitioned view 'PRICE_DIM' is not updatable as the target of a bulk operation How to solve this problem?
View Replies !
Partitioned View && Computed Column..
Hello, please enlighten me regarding an issue with partitioned view... There are 3 tables in my DB of a similar structure: CREATE TABLE Table1 (value1 varchar(1)) CREATE TABLE Table2 (value1 varchar(1)) CREATE TABLE Table3 (value1 varchar(1)) INSERT INTO Table1 (value1) SELECT 'a' UNION SELECT 'b' UNION SELECT 'c' INSERT INTO Table2 (value1) SELECT 'a' UNION SELECT 'b' UNION SELECT 'c' INSERT INTO Table3 (value1) SELECT 'a' UNION SELECT 'b' UNION SELECT 'c' As sometimes we need to access all data from these tables, a view has been created: CREATE VIEW AllData AS SELECT value1, '1' as table_id from Table1 UNION ALL SELECT value1, '2' as table_id from Table2 UNION ALL SELECT value1, '3' as table_id from Table3 The problem is that while running a query like SELECT * from AllData WHERE value1 = 'a' and table_id = '3' I see a table scan being performed on all 3 tables, not just table3 - i.e optimisation engine doesn't care for my table_id computed column and for that fact that required data is located ONLY in Table3. Is there any way to force optimiser to consider this column andrrebuild a plan? If not - how can I rebuild a view (I can't modify tables) to achieve that? Maybe create an index for a view? Thanks in advance. RTFM and search don't seem to clarify this for me...
View Replies !
Optimization Of Query On Partitioned View
Schema below. The execution plan shows that this query is correctly optimized to check only the underlying Employee_2008 table. select * from Employee where ReportingYear = '2008' This query is not optimized and checks both Employee_2008 and Employee_2007: declare @ry varchar(4) set @ry = '2008' select * from Employee where ReportingYear = @ry How can I get second query to be optimized correctly? Schema: CREATE TABLE [dbo].[Employee_2007]( [EmployeeID] [int] NOT NULL, [Name] [varchar](50) NOT NULL ) ON [PRIMARY] CREATE TABLE [dbo].[Employee_2008]( [EmployeeID] [int] NOT NULL, [Name] [varchar](50) NOT NULL ) ON [PRIMARY] CREATE VIEW [dbo].[Employee] AS SELECT '2007' ReportingYear, EmployeeID, Name FROM Employee_2007 UNION ALL SELECT '2008' ReportingYear, EmployeeID, Name FROM Employee_2008
View Replies !
Partitioned View With Computed Column
Using SQL Server 2005. Defined partitioned view with computed column. Computed column was a constant varchar. Ran a SELECT. According to Query Execution Plan, SQL did recognize the computed column as the partitioning column and used it to optimize the query. However MSDN says a computed column cannot be used as the partitioning column. Could someone from MS clarify?
View Replies !
Distributed Partitioned View With RPC (or DTC) Problem
I am setting up 3 Linked Servers (SERVER_A, SERVER_B and SERVER_C) in an isolated local network. They are all running SQL Server 2005 Developer Edition, all on XP SP2. On each server, I have a distributed partitioned view named WAREHOUSE_ALL that basically is the UNION of all WAREHOUSE tables. I am having trouble in running write (INSERT, UPDATE or DELETE) queries on the distributed partitioned view. The error returned was (run from SERVER_B) OLE DB provider "SQLNCLI" for linked server "SERVER_A" returned message "No transaction is active.". Msg 7391, Level 16, State 2, Line 7The operation could not be performed because OLE DB provider "SQLNCLI" for linked server "SERVER_A" was unable to begin a distributed transaction. However, executing a read (SELECT) query ran smoothly without error. I have done all the steps required as described in the article at http://support.microsoft.com/?kbid=873160 . Note that the only difference between the situation and our situation is the provider (SQLOLEDB and SQLNCLI), which I guess does not important. Unfortunately, the error still comes out. After reading heaps of other article, I suspected that there is something wrong with MSDTC. As far as I know, all the settings for MSDTC were set accordingly. Then, I ran DTCPing - http://www.microsoft.com/downloads/details.aspx?FamilyID=5e325025-4dcd-4658-a549-1d549ac17644&DisplayLang=en and the error returned was DTCping log file: C:Documents and SettingsAdministratorDesktoplSERVER_B2496RPC server is ready Please Start Partner DTCping before pinging ++++++++++++Validating Remote Computer Name++++++++++++ Please refer to following log file for details: C:Documents and SettingsAdministratorDesktoplSERVER_B2496.log Invoking RPC method on SERVER_C Problem:fail to invoke remote RPC method Error(0x5) at dtcping.cpp @303 -->RPC pinging exception -->5(Access is denied.) RPC test failed And here is the log file: Platform:Windows XP IP Configure Information Host Name . . . . . . . . . : SERVER_B DNS Servers . . . . . . . . : 129.78.99.2 Node Type . . . . . . . . . : NetBIOS Scope ID. . . . . . : IP Routing Enabled. . . . . : no WINS Proxy Enabled. . . . . : no NetBIOS Resolution Uses DNS : no Ethernet adapter {4404F3CB-F4B7-4990-912C-E69721C885B1}: Description . . . . . . . . : 3Com EtherLink XL 10/100 PCI TX NIC (3C905B-TX) #2 - Packet Scheduler Miniport Physical Address. . . . . . : 00-01-02-85-B8-A9 DHCP Enabled. . . . . . . . : no IP Address. . . . . . . . . : 172.19.102.35 Subnet Mask . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . : 172.19.102.250 DHCP Server . . . . . . . . : 255.255.255.255 Primary WINS Server . . . . : 0.0.0.0 Secondary WINS Server . . . : 0.0.0.0 Lease Obtained. . . . . . . : Thu Jan 01 00:00:00 1970 Lease Expires . . . . . . . : Thu Jan 01 00:00:00 1970 ++++++++++++lmhosts.sam++++++++++++ ++++++++++++hosts ++++++++++++ 127.0.0.1 localhost ++++++++++++++++++++++++++++++++++++++++++++++ DTCping 1.9 Report for SERVER_B ++++++++++++++++++++++++++++++++++++++++++++++ RPC server is ready ++++++++++++Validating Remote Computer Name++++++++++++ 10-05, 17:10:54.769-->Start DTC connection test Name Resolution: SERVER_C-->172.19.102.36-->SERVER_C 10-05, 17:11:09.781-->Start RPC test (SERVER_B-->SERVER_C) Problem:fail to invoke remote RPC method Error(0x5) at dtcping.cpp @303 -->RPC pinging exception -->5(Access is denied.) RPC test failed I guess it could be due to port problem, which I have already opened in the Windows Firewall. There is one article which is confusing me -> Update to automatically open port 135 in Windows Firewall when a TCP or a UDP RPC server registers with the endpoint mapper at http://support.microsoft.com/kb/838191 (This article shows automatic opening of port 135!) Please help me. Thanks.
View Replies !
Triggers On Tables Underlying A Partitioned View
We have a partitioned view with 4 underlying tables. The view and eachof the underlying tables are in seperate databases on the same server.Inserts and deletes on the view work fine. We then add insert anddelete triggers to each of the underlying tables. The triggers modifya different set of tables in the same database as the view (differentthan the underlying table). The problem is those triggers aren't firedwhen inserting or deleteing via the view. Inserting or deleteing theunderlying table directly causes the the triggers to fire, but not whenthe tables are accessed as a result of using the view.Am I missing something? The triggers are 'for insert' and 'fordelete'. No 'instead of' or 'after' triggers.
View Replies !
Unable To Create A Partitioned Indexed View
Hi, While creating an indexed view with the command : create unique clustered index idx_atrid on account_transactions (policy) there is a check constraint on the policy column of the tables used in this view. The following error is encountered Cannot index the view 'test.dbo.account_transactions'. It contains one or more disallowed constructs. Can anyone help?
View Replies !
Insertion Faild In Partitioned View In Sql Server 7.0
I have a problem while I try to insert data into a partioned view I am getting the following error. Server: Msg 4436, Level 16, State 12, Line 9 UNION ALL view 'sales_all' is not updatable because a partitioning column was not found. Any thoughts USE pubs CREATE TABLE sales_monthly ( sales_month int NOT NULL , sales_qty int NOT NULL ) GO CREATE TABLE sales_jan ( sales_month int NOT NULL, sales_qty int NOT NULL ) GO CREATE TABLE sales_feb ( sales_month int NOT NULL, sales_qty int NOT NULL ) GO ALTER TABLE sales_feb WITH NOCHECK ADD CONSTRAINT PK_sales_feb PRIMARY KEY CLUSTERED ( sales_month ) , CONSTRAINT CK_sales_feb CHECK (sales_month = 2) GO ALTER TABLE sales_jan WITH NOCHECK ADD CONSTRAINT PK_sales_jan PRIMARY KEY CLUSTERED ( sales_month ) , CONSTRAINT CK_sales_jan CHECK (sales_month = 1) GO
View Replies !
Query Against Partitioned View Is Not Optimized Due To CONVERT_IMPLICIT
We have a situation where queries against a partitioned view ignore a suitable index and perform a table scan (against 200+MB of data), where the same query on the underlying table(s) results in a 4 page index seek. I can€™t find any mention of the situation, so I€™m trying a post here. We€™re running SQL Server 2005 Enterprise edition sp2 on Windows 2003 Enterprise Edition sp1 on a two node cluster, and it also occurs on a stand-alone development box with Developer edition. We have four tables, named Options#0, Options#1, Options#2, and Options#3. All are almost identical (script generated by SSMS and edited down a bit): SET ANSI_NULLS OFF SET QUOTED_IDENTIFIER ON CREATE TABLE [dbo].[Options#0]( [ControlID] [tinyint] NOT NULL CONSTRAINT [DF_Options#0__ControlID] DEFAULT ((0)), [ModelCode] [char](8) NOT NULL, [EquipmentID] [int] NOT NULL, [AdjustmentContextID] [int] NOT NULL, [EquipmentCode] [char](2) NOT NULL, [EquipmentTypeCode] [char](1) NOT NULL, [Description] [varchar](50) NOT NULL, [DisplayOrder] [smallint] NOT NULL, [IsStandard] [bit] NOT NULL, [Priority] [tinyint] NOT NULL, [Status] [bit] NOT NULL, [Adjustment] [int] NOT NULL, CONSTRAINT [PK_Options#0] PRIMARY KEY CLUSTERED ( [ModelCode] ASC, [EquipmentID] ASC, [AdjustmentContextID] ASC, [ControlID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] ALTER TABLE [dbo].[Options#0] WITH CHECK ADD CONSTRAINT [CK_Options#0__ControlID] CHECK (([ControlID]=(0))) ALTER TABLE [dbo].[Options#0] CHECK CONSTRAINT [CK_Options#0__ControlID] The only differences between the tables are in the names and in the value defaulted to and CHECKed, which matches the table name (to support the partitioned view, of course). We receive and load data ever week and every two month, and use an unlikely algorithm to load and manage its availability by running an ATLER on the view (to maintain the access rights defined for the hosting environment). Scripted out via SSMS, the view looks like: SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON CREATE VIEW [dbo].[Options] AS select * from Options#1 union all select * from Options#3 The problem is that when we issue a query like SELECT count(*) from Options where ControlID = 1 and ModelCode = '2004NIC9' The resulting query (as checked via the query plan and SET STATISTICS IO on) will get €œpartitioned€?, running against the proper table, but it will ignore the query, perform a table scan, and churn through 200+MB of data. A Similar query run against the underlying table SELECT count(*) from Options#1 where ControlID = 1 and ModelCode = '2004NIC9' (with or without the ControlID = 1 clause) will perform a Clustered Index Seek and read maybe 4 pages. Analyzing the execution plan shows that the table query work like you€™d think, but for the query against the view we get a Clustered Index Scan, with predicate: [DBName].[dbo].[Options#1].[ControlID]=(1) AND CONVERT_IMPLICIT(char(8),[ DBName].[dbo].[Options#1].[ModelCode],0)=€™2004NIC9€™ I get the same results when explicitly listing all columns in the view. The code page on the view and tables is the same (as determined by checking properties via SSMS). Why is the table data column being implicitly converted to the data type that it already is? Why does this occur when working with the partitioned view but not with the actual table? Can this behavior be controlled or modified without losing the (incredibly useful) data loading management benefits of the partitioned view? I€™m guessing (and hoping) it€™s some subtle quirk or mis-setting, please set me on the right path! Philip Kelley
View Replies !
Partitioned View Broken After Moving Table To New Filegroup
I am using SQL Server 2000, SP3.I created an updatable partitioned view awhile ago and it has beenrunning smoothly for some time. The partition is on a DATETIME columnand it is partitioned by month. Each month a stored procedure isscheduled that creates the new month's table, and alters the view toinclude it. Again... working like a charm for quite some time.This past weekend I moved some of the first tables onto a new filegroup. I did this through Enterprise Manager, by going into designmode for the table, then going into the properties for the table andchanging the file group there as well as in all of the indexes. Nowthe partitioned view is no longer updatable. It gives the errormessage: "UNION ALL view '<view name>' is not updatable because apartitioning column was not found."I have extracted the DDL for all of the partition tables and comparedthem and they all look the same. I checked and then double-checked theCHECK constraints to make sure that they were all valid and they are.If I remove the tables that I moved to the new file group from theview, then it is once again updatable, but when I put them back in itfails again.Any ideas? If you would like samples of the code then I can send italong, but it's rather large, so I have not included it here.Thanks!Thomas R. Hummel
View Replies !
Incorrect Query Plan With Partitioned View On SQL 2000
I have a partitioned view containing 4 tables (example follows at end) The query plan generated on a select correctly accesses just one of the tables The query plan generated on an update always accesses all four of the tables. I thought that it should only access the partition required to satisfy the update. Can anyone please advise whether: a) Is this is expected behaviour? b) Is the partitioned view incorrectly configured in some way? c) Is there is a known bug in this area Note that the behaviour is the same with SP1 on SQL2000 I would be very grateful for any advice Thanks Stefan Bennett Example follows --Create the tables and insert the values CREATE TABLE Sales_West ( Ordernum INT, total money, region char(5) check (region = 'West'), primary key (Ordernum, region) ) CREATE TABLE Sales_North ( Ordernum INT, total money, region char(5) check (region = 'North'), primary key (Ordernum,region) ) CREATE TABLE Sales_East ( Ordernum INT, total money, region char(5) check (region = 'East'), primary key (Ordernum,region) ) CREATE TABLE Sales_South ( Ordernum INT, total money, region char(5) check (region = 'South'), primary key (Ordernum,region) ) GO INSERT Sales_West VALUES (16544, 2465, 'West') INSERT Sales_West VALUES (32123, 4309, 'West') INSERT Sales_North VALUES (16544, 3229, 'North') INSERT Sales_North VALUES (26544, 4000, 'North') INSERT Sales_East VALUES ( 22222, 43332, 'East') INSERT Sales_East VALUES ( 77777, 10301, 'East') INSERT Sales_South VALUES (23456, 4320, 'South') INSERT Sales_South VALUES (16544, 9999, 'South') GO --create the view that combines all sales tables CREATE VIEW Sales_National AS SELECT * FROM Sales_West UNION ALL SELECT * FROM Sales_North UNION ALL SELECT * FROM Sales_East UNION ALL SELECT * FROM Sales_South GO --Look at execution plan for this query -- This correctly only accesses the South partition SELECT * FROM sales_national WHERE region = 'south' -- Look at execution plan for update -- This accesses all partitions - Why? update sales_national set total = 100 where ordernum = 23456;
View Replies !
Query Server To Find All Partitioned Tables, Partition Name, Column Used, Partitioned By
I want to find a way to get partition info for all the tables in all the databases for a server. Showing database name, table name, schema name, partition by (maybe; year, month, day, number, alpha), column used in partition, current active partition, last partition (for date partitions I want to know if the partition goes untill 2007, so I can add 2008) all I've come up with so far is: Code Block SELECT distinct o.name From sys.partitions p inner join sys.objects o on (o.object_id = p.object_id) where o.type_desc = 'USER_TABLE' and p.partition_number > 1
View Replies !
How To Use CURSOR For Updating Records
Hello Everyone, I have a table with 5 columns (col1, col2, col3, col4). I want to do is: 1) To check if any two records are duplicates (if the the values in col1 of record A are identical to Record B, two records are considered as duplicates); 2) if two records are duplicate, I want to mark Record B as "Dup" in col4 ; 3) move the data of Col2 of Record B to col3 of Record A. I have tried to use CURSOR for the job. I would appreciate if anyone can give me some hints for updating records using Cursor. My script looks like this: CREATE PROC Mark_duplicate AS DECLARE @var1_a, /* To hold the data from Record A */ @var2_a, @var3_a, @var4_a, @var5_a, @var1_b, /* To hold the data from Record B */ @var2_b, @var3_b, @var4_b, @var4_b, /*** Create a CURSOR ***/ DECLARE Dup CURSOR FOR SELECT col1, col2, col3, col4 FROM TableA ORDER BY col1, col2 FOR UPDATE OF col1, col2, col3, col4 /**** OPEN the CURSOR ****/ OPEN Dup FETCH NEXT FROM Dup into @var1_a, @var2_a, @var3_a, @var4_a WHILE ( @@FETCH_STATUS =0 ) BEGIN FETCH NEXT FROM Dup into @var1_b, @var2_b, @var3_b, @var4_b WHILE ( @@FETCH_STATUS =0 ) BEGIN If ( @var1_a = var1_b ) THEN . .Updating statements . . ELSE SET @VAR1_a = @var1_b, @VAR2_a = @var2_b, @VAR3_a = @var3_b, @VAR4_a = @var4_b FETCH NEXT FROM Dup into @var1_b, @var2_b, @var3_b, var4_b END END CLOSE DUP . . . Thanks a lot. Have a good day! Lunjun
View Replies !
Updating My View Changes My View Content
I have this view in SQL server: CREATE VIEW dbo.vwFeat AS SELECT dbo.Lk_Feat.Descr, dbo.Lk_Feat.Price, dbo.Lk_Feat.Code, dbo.SubFeat.SubNmbr FROM dbo.Lk_Feat INNER JOIN dbo.SubFeat ON dbo.Lk_Feat.Idf = dbo.SubFeat.Idt When ever I open using SQL Entreprise manager to edit it by adding or removing a field i inserts Expr1,2.. and I don t want that. The result I get is: SELECT dbo.Lk_Feat.Descr AS Expr1, dbo.Lk_Feat.Price AS Expr2, dbo.Lk_Feat.Code AS Expr3, dbo.SubFeat.SubNmbr AS Expr4 FROM dbo.Lk_Feat INNER JOIN dbo.SubFeat ON dbo.Lk_Feat.Idf = dbo.SubFeat.Idt I don t want Entreprise manager to generate the Expr fields since I use the real fields in my application. Thanks for help
View Replies !
It Is Very Slow At Updating By Use Cursor (fetch Method)
Hi all, I got a problem. I am working on DTS package. The last step is updating a table field. I wrote a stored procedure as below: CREATE PROCEDURE [Update_product_manufacturer] AS Declare @product_id int Declare @supplier_name VarChar (255) Declare ValueCursor Cursor For select product.product_id, [P21_SUPPLIER_id_name_ke].[supplier_name] from [VARIANT],[P21_INV_MAST_uid_itenID_weight_ke],[product], [P21_INVENTORY_SUPPLIER_uid_supplierID_price_cost_k e],[P21_SUPPLIER_id_name_ke] where [product].product_id = [VARIANT].[product_id] and [P21_INV_MAST_uid_itenID_weight_ke].[item_id]=[VARIANT].[SKU] AND [P21_INV_MAST_uid_itenID_weight_ke].[inv_mast_uid]=[P21_INVENTORY_SUPPLIER_uid_supplierID_price_cost_k e].[inv_mast_uid] AND [P21_SUPPLIER_id_name_ke].[supplier_id]=[P21_INVENTORY_SUPPLIER_uid_supplierID_price_cost_k e].[supplier_id] order by [product].[product_id] for read only Open ValueCursor while (0 = 0) begin fetch next from ValueCursor Into @product_id, @supplier_name update product set manufacturer = @supplier_name where product_id = @product_id end close ValueCursor Deallocate ValueCursor Notes: Table: Product has 28,000 rows, other tables with 28,000 - 56,000 rows it's been 2 hours, the job is still working. Who has this kind of experience? How can I make updating quickly? Thanks, Kevin Zhang
View Replies !
Create View From Cursor
I have multiple locations that I want to create views for eachindividual location.I am using a cursor to create the views for each location. So, thecursor grabs site #1 then <should> create view_site_#1, then grab site#2 and <should> create view_site_#2.For some reason it doesn't like the view name with the @site in it.Any ideas of how to get this done?Here's the cursor...declare @site varchar(5)declare c_site cursor forselect station from VHAISLCAUDIA.VISN_SITEorder by stationopen c_sitefetch from c_siteinto @sitewhile (@@fetch_status = 0)beginCREATE VIEW Site_All_Data_+ @siteASSELECT *FROM dbo.[600_All_Suggested_Data]WHERE (Site = @site)Print 'View for ' + @site + ' Created'fetch next from c_site into @siteendclose c_sitedeallocate c_sitereturnend
View Replies !
Updating A View
Hi, In what way a view can be updated / inserted / deleted (records)? Kinldy make me clear on this. Have gone through lot many blogs / articles and got more and more confused. Thanks, Rahul Jha
View Replies !
Updating A View
I don't know if this is possible but, I have a view that retrieves data between 2 dates. The data is then exported to an Excel spreadsheet. My question is this: Is there some way I can automatically change the date in my alter view window? For example, I want to extract the data at the beginning of each month for the previous month. Then whoever is looking at the data can then refresh every month to get the previous months data. I want something that will automatically update my view every month with the previous month, without me having to go in and physically doing it. Is there a way, and how complicated would it be? Thanks.
View Replies !
Updating A View Using C#
Hello everyone, I'm using sqlserver 2005 with SQL management studio.I have a view and it has a problem. The problem is that...SQL management studio automatically generated some sql script for me to update the view.But,it doesn't work.HELP ME please! This is the script it gave me... ------------- UPDATE [skips].[dbo].[Schedule] SET [ContractId] = <ContractId, int,> ,[DriverId] = <DriverId, int,> ,[TruckId] = <TruckId, int,> ,[Completed] = <Completed, bit,> ,[Day] = <Day, varchar,> WHERE <Search Conditions,,> -------------- When I try to execute it...I get this error , Msg 102, Level 15, State 1, Line 2 Incorrect syntax near '<'. How do I make this work and update the view? Thanks so much in advance
View Replies !
Cursor, Query, View And Recordset
Could someone help me by answering the questions below?What's a cursor?What's difference between Query and View?Is a RecordSet just part of a table? Can it be part of a query of view?If the content in a table changed, is it necessary for a old recordset torenew itself by do "Requery()"?Thanks for your help!
View Replies !
View For Updating Hyperlinks
I have a database that has SQL 2000 as the engine and Access 2003 on the front end, we scan our documents and hyperlink them through Access, the address is stored in SQL Server but we are wanting to move SQL, the scanned documents along witht he ADP over to a different server so instead of the files linking to \gcfso1 they will link to \gcfsql. is there a way to update the address link in SqL to link to \gcfsql as an update view rather then relinking them by hand???? Help
View Replies !
Updating Data In A View
Hello everyone, Can someone help me with updating data into a view using triggers? I am struggling hard to write a trigger or stored procedure to update the values on the base tables of the view. Please help me out... Thanks, Godwin
View Replies !
Updating A View Through A Stored Procedure.
Hi i have a page in which a user fills out info on a page, the problem i am getting is that when the save button is clicked all text box values apart from one are saving to the database this field is the "constructor_ID" field. The save button performs a stored procedure, however there is a view which is doing something as well, would it be possible to write a stored procedure which would update the view at the same time? CREATE PROCEDURE sp_SurveyMainDetails_Update @Constructor_ID int,@SurveyorName_ID int,@Survey_Date char(10),@Survey_Time char (10),@AbortiveCall bit,@Notes text,@Survey_ID int,@User_ID int,@Tstamp timestamp out AS DECLARE @CHANGED_Tstamp timestampDECLARE @ActionDone char(6)SET @ActionDone = 'Insert' SET @CHANGED_Tstamp = (SELECT Tstamp FROM tblSurvey WHERE Survey_ID = @Survey_ID)IF @Tstamp <> @CHANGED_Tstamp --AND @@ROWCOUNT =0 BEGIN SET @Tstamp = @CHANGED_Tstamp RAISERROR('This survey has already been updated since you opened this record',16,1) RETURN 14 ENDELSE BEGIN SELECT * FROM tblSurvey WHERE Constructor_ID = @Constructor_ID AND --Contractor_ID = @Contractor_ID AND Survey_DateTime = Convert(DateTime,@Survey_Date + ' ' + LTRIM(RTRIM(@Survey_Time)), 103) AND IsAbortiveCall = @AbortiveCall IF @@ROWCOUNT>0 SET @ActionDone = 'Update' UPDATE tblSurvey SET Constructor_ID = @Constructor_ID , SurveyorName_ID = @SurveyorName_ID , Survey_DateTime = Convert(DateTime,@Survey_Date + ' ' + LTRIM(RTRIM(@Survey_Time)), 103) , IsAbortiveCall = @AbortiveCall , Note = @Notes WHERE Survey_ID = @Survey_ID AND Tstamp = @Tstamp IF @@error = 0 begin exec dhoc_ChangeLog_Insert 'tblSurvey', @Survey_ID, @User_ID, @ActionDone, 'Main Details', @Survey_ID end else BEGIN RAISERROR ('The request has not been proessed, it might have been modifieid since you last opened it, please try again',16,1) RETURN 10 END SELECT * FROM tblSurvey WHERE Survey_ID=@Survey_ID END --Make sure this has saved, if not return 10 as this is unexpected error --SELECT * FROM tblSurvey DECLARE @RETURN_VALUE tinyintIF @@error <>0 RETURN @@errorGO This is the view; CREATE VIEW dbo.vw_Property_FetchASSELECT dbo.tblPropertyPeriod.Property_Period, dbo.tblPropertyType.Property_Type, dbo.tblPropertyYear.Property_Year, dbo.tblProperty.Add1, dbo.tblProperty.Add2, dbo.tblProperty.Add3, dbo.tblProperty.Town, dbo.tblProperty.PostCode, dbo.tblProperty.Block_Code, dbo.tblProperty.Estate_Code, dbo.tblProperty.UPRN, dbo.tblProperty.Tstamp, dbo.tblProperty.Property_ID, dbo.tblProperty.PropertyStatus_ID, dbo.tblProperty.PropertyType_ID, dbo.tblProperty.Correspondence_Add4, dbo.tblProperty.Correspondence_Add3, dbo.tblProperty.Correspondence_Add2, dbo.tblProperty.Correspondence_Add1, dbo.tblProperty.Correspondence_Phone, dbo.tblProperty.Correspondence_Name, dbo.tblPropertyStatus.Property_Status, dbo.tblProperty.Floor_Num, dbo.tblProperty.Num_Beds, dbo.vw_LastSurveyDate.Last_Survey_Date, dbo.tblProperty_Year_Period.Constructor_ID, dbo.tblProperty_Year_Period.PropertyPeriod_ID, dbo.tblProperty_Year_Period.PropertyYear_ID, LTRIM(RTRIM(ISNULL(dbo.tblProperty.Add1, ''))) + ', ' + LTRIM(RTRIM(ISNULL(dbo.tblProperty.Add2, ''))) + ', ' + LTRIM(RTRIM(ISNULL(dbo.tblProperty.Add3, ''))) + ', ' + LTRIM(RTRIM(ISNULL(dbo.tblProperty.PostCode, ''))) AS Address, dbo.tblProperty.TenureFROM dbo.tblPropertyType RIGHT OUTER JOIN dbo.tblProperty LEFT OUTER JOIN dbo.tblProperty_Year_Period ON dbo.tblProperty.Property_ID = dbo.tblProperty_Year_Period.Property_ID LEFT OUTER JOIN dbo.vw_LastSurveyDate ON dbo.tblProperty.Property_ID = dbo.vw_LastSurveyDate.Property_ID LEFT OUTER JOIN dbo.tblPropertyStatus ON dbo.tblProperty.Status_ID = dbo.tblPropertyStatus.PropertyStatus_ID ON dbo.tblPropertyType.PropertyType_ID = dbo.tblProperty.PropertyType_ID LEFT OUTER JOIN dbo.tblPropertyPeriod ON dbo.tblProperty.PropertyPeriod_ID = dbo.tblPropertyPeriod.PropertyPeriod_ID LEFT OUTER JOIN dbo.tblPropertyYear ON dbo.tblProperty.PropertyYear_ID = dbo.tblPropertyYear.PropertyYear_ID
View Replies !
View Not Updating With Table Schema Changes
I notice that when I change my table schema, the view that was created based on the older schema remains using the older schema, and when I try running it, it will give me error. I assume that's because the view is still using the old execution plan? Is there a way to force an automatic recompilation of execution plans for all views when there is a change to the underlying table? Thanks!
View Replies !
Updating Partitioning View Though ODBC
Can a CRecordset update a SQL Server Partitioning View? We have an updateable (confirmed via testing)partitioned view through which we would like to update/append rows using a MFC CRecordset though ODBC. The program currently updates the original base table which has been partitioned and needs to be modified to use the view (as opposed to hitting the underlying 24 partitions, ugh). When the recordset is opened on the view it is appearing as read-only. All the columns in the view (and underlying table) are referenced in the recordset. I have tried setting the recordset as a dynaset and a snapshot. I am using Visual C++ .Net 2005, SQL Server 2005 sp2. and SQL Native Client (SQLNCLI ). I ran a ODBC trace and can see that the driver is changing the concurrency causing MFC to flag the recordset as read-only. I can also see in the trace the ODBC version is 3.53.0000. Any help would be appreciated. TIA, Scott
View Replies !
Updating A View In Sqlserver 2005
Hello everyone, I'm using sqlserver 2005 with SQL management studio.I have a view and it has a problem. The problem is that...SQL management studio automatically generated some sql script for me to update the view.But,it doesn't work.HELP ME please! This is the script it gave me... ------------- UPDATE [skips].[dbo].[Schedule] SET [ContractId] = <ContractId, int,> ,[DriverId] = <DriverId, int,> ,[TruckId] = <TruckId, int,> ,[Completed] = <Completed, bit,> ,[Day] = <Day, varchar,> WHERE <Search Conditions,,> -------------- When I try to execute it...I get this error , Msg 102, Level 15, State 1, Line 2 Incorrect syntax near '<'. How do I make this work and update the view? Thanks so much in advance
View Replies !
Updating Grid View That Has Dropdown Lists
I have gridview bound with SqlDataSource control. One of the grid columns is a dropdown list which is populated programatically, (the gridview has template column with edittemplate field with dropdown list), dropdown Value contains of course collection of IDs.Please tell me how to declare UpdateCommand which will update the row with the dropdown list. The problem is with parameter regarding the column with dropdown list. When i declare this parameter and bind it to SelectedValue property of the dropdownlist from edittemplate tag - it doesnt work, because datasource control cannot see this dropdown list. So, how am i supposed to declare the ID of the row being updated in <updateParameters>? Thanks in advance!
View Replies !
Dynamic Cursor Versus Forward Only Cursor Gives Poor Performance
Hello,I have a test database with table A containing 10,000 rows and a tableB containing 100,000 rows. Rows in B are "children" of rows in A -each row in A has 10 related rows in B (ie. B has a foreign key to A).Using ODBC I am executing the following loop 10,000 times, expressedbelow in pseudo-code:"select * from A order by a_pk option (fast 1)""fetch from A result set""select * from B where where fk_to_a = 'xxx' order by b_pk option(fast 1)""fetch from B result set" repeated 10 timesIn the above psueod-code 'xxx' is the primary key of the current Arow. NOTE: it is not a mistake that we are repeatedly doing the Aquery and retrieving only the first row.When the queries use fast-forward-only cursors this takes about 2.5minutes. When the queries use dynamic cursors this takes about 1 hour.Does anyone know why the dynamic cursor is killing performance?Because of the SQL Server ODBC driver it is not possible to havenested/multiple fast-forward-only cursors, hence I need to exploreother alternatives.I can only assume that a different query plan is getting constructedfor the dynamic cursor case versus the fast forward only cursor, but Ihave no way of finding out what that query plan is.All help appreciated.Kevin
View Replies !
Could Not Complete Cursor Operation Because The Set Options Have Changed Since The Cursor Was Declared.
I'm trying to implement a sp_MSforeachsp howvever when I call sp_MSforeach_worker I get the following error can you please explain this problem to me so I can over come the issue. Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 31 Could not complete cursor operation because the set options have changed since the cursor was declared. Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 32 Could not complete cursor operation because the set options have changed since the cursor was declared. Msg 16917, Level 16, State 1, Procedure sp_MSforeach_worker, Line 153 Cursor is not open. here is the stored procedure: Alter PROCEDURE [dbo].[sp_MSforeachsp] @command1 nvarchar(2000) , @replacechar nchar(1) = N'?' , @command2 nvarchar(2000) = null , @command3 nvarchar(2000) = null , @whereand nvarchar(2000) = null , @precommand nvarchar(2000) = null , @postcommand nvarchar(2000) = null AS /* This procedure belongs in the "master" database so it is acessible to all databases */ /* This proc returns one or more rows for each stored procedure */ /* @precommand and @postcommand may be used to force a single result set via a temp table. */ declare @retval int if (@precommand is not null) EXECUTE(@precommand) /* Create the select */ EXECUTE(N'declare hCForEachTable cursor global for SELECT QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME) FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = ''PROCEDURE'' AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME)), ''IsMSShipped'') = 0 ' + @whereand) select @retval = @@error if (@retval = 0) EXECUTE @retval = [dbo].sp_MSforeach_worker @command1, @replacechar, @command2, @command3, 0 if (@retval = 0 and @postcommand is not null) EXECUTE(@postcommand) RETURN @retval GO example useage: EXEC sp_MSforeachsp @command1="PRINT '?' GRANT EXECUTE ON ? TO [superuser]" GO
View Replies !
Updating A Table By Both Inserting And Updating In The Data Flow
I am very new to SQL Server 2005. I have created a package to load data from a flat delimited file to a database table. The initial load has worked. However, in the future, I will have flat files used to update the table. Some of the records will need to be inserted and some will need to update existing rows. I am trying to do this from SSIS. However, I am very lost as to how to do this. Any suggestions?
View Replies !
Partitioned Views
I would like to break up a very large table into about ten smaller ones. With partitioning to be efficient the columns in the check constraint need to be used when accessing the view. The problem is the table has a composite primary key made up of LocationID/ProductID. With another composite index on ProductID/LocationID. This is accessed both ways from our applications. I would like to partition the table by LocationID. But then when called by ProductID a scan of all tables in the view would have to be done. In Oracle there is something called a global index that would solve this. Is there anything similar in SQL Server or does anybody have a work around? Thanks, Rob
View Replies !
Partitioned Views
Hi, I've starting to explore the Distributed Partitoned Views, in order to use it in the next project, and I've found the article: "MS SQL Server Distributed Partitioned Views" By Don Schlichting I came across the following problem: While running sample: USE test GO CREATE VIEW AllAuthors AS SELECT * FROM AuthorsAM, TEST1.test.dbo.AuthorsNZ GO I got the error message: Server: Msg 4506, Level 16, State 1, Procedure AllAuthors, Line 5 Column names in each view or function must be unique. Column name 'au_lname' in view or function 'AllAuthors' is specified more than once. Could anyone please explain? Can't i use the same column names in both tables? Regards, Yifat
View Replies !
Partitioned Tables
Hello, I am implementing a table partitioning on our database with TSQL. At the moment (it is under developing) the data are correctly located in the relavant file group. Our target is to meke that the oldest partions/File groups can be backup and removed from the database. This to reduce the size of DB (time period is used for partitioning). Then, if the need arises, restoring the filegroup to make reporting or analysis. Take care that data are conitnuosly added and thus new File groups are added to represent the new time period (eg: new file group is the new month). Based on your experience is it possible a solution like that? Thank
View Replies !
PARTITIONED VIEWS
You could separate your tables by using PARTITIONED VIEWS. Also, you could send each partitioned table on a different filegroup and if it's possible, you could move this filegroups on different physical disks ( historical ). You will get a better performance 'cause you have the current information on a smaller file and when you need to get historical info the sql server will get the info from the others filegroups. I send you an example of how to create PARTITIONED VIEWS. Good Luck. -reate table PeopleSJ ( PeopleID int , FullName nvarchar(100) not null, StateCode nvarchar(2) not null check ( StateCode = 'SJ' ), constraint PK_PeopleSJ primary key ( StateCode, PeopleID ) ) go create table PeopleAL ( PeopleID int , FullName nvarchar(100) not null, StateCode nvarchar(2) not null check ( StateCode = 'AL' ), constraint PK_PeopleAL primary key ( StateCode, PeopleID ) ) go create table PeopleHR ( PeopleID int , FullName nvarchar(100) not null, StateCode nvarchar(2) not null check ( StateCode = 'HR' ), constraint PK_PeopleHR primary key ( StateCode, PeopleID ) ) go create view People as select * from PeopleSJ union all select * from PeopleAL union all select * from PeopleHR go insert into People ( PeopleID, FullName, StateCode ) values ( 1, 'Abril Jimenez', 'AL' ); insert into People ( PeopleID, FullName, StateCode ) values ( 2, 'Joshua Jimenez', 'AL' ); insert into People ( PeopleID, FullName, StateCode ) values ( 3, 'Yajaira Delgado', 'SJ' ); insert into People ( PeopleID, FullName, StateCode ) values ( 4, 'Roy Jimenez', 'AL' ); insert into People ( PeopleID, FullName, StateCode ) values ( 5, 'Victor Esquivel', 'HR' ); insert into People ( PeopleID, FullName, StateCode ) values ( 6, 'Diego Rojas', 'HR' ); insert into People ( PeopleID, FullName, StateCode ) values ( 7, 'Laura Fonseca', 'HR' ); insert into People ( PeopleID, FullName, StateCode ) values ( 8, 'Alex Diaz', 'SJ' ); insert into People ( PeopleID, FullName, StateCode ) values ( 9, 'Erick Vargas', 'SJ' ); go select * from People go select * from PeopleAL; select * from PeopleSJ; select * from PeopleHR; go select * from People where StateCode = 'AL' go create table PeoplePU ( PeopleID int , FullName nvarchar(100) not null, StateCode nvarchar(2) not null check ( StateCode = 'PU' ), constraint PK_PeoplePU primary key ( StateCode, PeopleID ) ) go alter view People as select * from PeopleSJ union all select * from PeopleAL union all select * from PeopleHR union all select * from PeoplePU go insert into People ( PeopleID, FullName, StateCode ) values (10, 'Juanito Perez', 'PU' ); insert into People ( PeopleID, FullName, StateCode ) values (11, 'Maria Lopez', 'PU' ); go select * from People go select * from PeopleAL; select * from PeopleSJ; select * from PeopleHR; select * from PeoplePU; go select * from People where StateCode in ('AL', 'PU') go
View Replies !
Partitioned Tables
When do partitioned tables/indexes become beneficial? When a table has several million rows? Hundreds of millions of rows? My tables all have clustered indexes based on the bigint identity PK. I am considering partitioning some of the larger tables by year. If the field I use is not part of the current clustered index then I can't use create index to create my partitions? I need to create an empty table for each year and then use the Alter Table switch? I have header/detail/sub-detail tables. As long as I create the partition function using a similar date field the partitions will be able to be joined? How do I insure my indexes will be aligned? Once I set up the partitions I assume new rows will be stored in the proper partitions based on the value of the date field. I've read BOL, etc & they are good sources for theory but I need a "Building Partitions for Dummies" type paper with step by step explanations. Anything out there like that? Thanks.
View Replies !
Maintaining Partitioned Views
Hello,I have a large set of data that I have set up as a partitioned view.The view is partitioned by a datetime column and the individual tableseach represent one month's worth of data. I need to keep at least twoyear's worth of data at all times, but after two years I can archivethe data. A sample of the code used is below. It is simplified forspace reasons.My question is, how do other people maintain the database in this typeof scenario? I could create all of the tables necessary for the nextyear and then go through that at the end of each year (archive tablesover two years, add new tables, and change the view), but I was alsothinking that I might be able to write a stored procedure that runsonce a month and does all three of those tasks automatically. It seemslike a lot of dynamic SQL code though for something like that.Alternatively, I could write VB code to handle it in a DTS package.So, my question again is, how are others doing it? Any suggestions?Thanks!-Tom.CREATE TABLE [dbo].[Station_Events_200401] ([event_time] [datetime] NOT NULL ,[another_column] [char] (8) NOT NULL )GOCREATE TABLE [dbo].[Station_Events_200402] ([event_time] [datetime] NOT NULL ,[another_column] [char] (8) NOT NULL )GOCREATE VIEW Station_EventsASSELECT event_time,another_columnFROM Station_Events_200401UNION ALLSELECT event_time,another_columnFROM Station_Events_200402GO
View Replies !
|