Error: Table Schema Changed After The Cursor Is Declared
Hi,
I have a package which loads data from one sql server table to another. I am loading 15million records in that. Earlier I tested that package with smaller data (less than a million) and it worked fine. So, I put it in production to load that 15 million records. But strangely after loading over 1.5million records, the job aborted with error at destination. The log says 'the table schema has changed after the cursor is declared'. But there is no change made in both destination as well as source.
In my package I am using a 'OLEDB Source' to read data from a SQL Server table, using 'Script component' making some changes and loading data to a sql server table using 'OLE DB Destination'. Both source and destination are in same server, but under different schema.
Do you have any idea about the problem?
Thanks.
View Complete Forum Thread with Replies
Related Forum Messages:
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 !
Set Value For Variable In A Declared Cursor
Hi, I have a problem on setting the value for the variable in a declared cursor. Below is my example, I have declared the cursor c1 once at the top in a stored procedure and open it many times in a loop by setting the variable @str_var to different values. It seems the variable cannot be set after the cursor declared. Please advise how can I solve this issue. ------------------------------------------------------------------------ DECLARE @str_var VARCHAR(10) DECLARE @field_val VARCHAR(10) DECLARE c1 CURSOR LOCAL FOR SELECT field1 FROM tableA WHERE field1 = @str_var WHILE (Sometime TRUE) BEGIN .... SET @str_var = 'set to some values, eg. ABC123, XYZ123' OPEN c1 FETCH c1 INTO @field_val WHILE (@@fetch_status != -1) BEGIN PRINT @field_val ... FETCH c1 INTO @field_val END CLOSE c1 END DEALLOCATE c1 ---------------------------------------------------------------------- Thanks a lots, Vincent
View Replies !
Cursor Declared With Variable In Where Clause
When I execute next query on sqlserver 6.5 nested in stored procedure I can see that 'open testCursor' selected rows using new value of @var. When I execute query on sqlserver 7.0 I can see that 'open testCursor' selected rows using value of @var before 'declare ... cursor'. Is there any way to force sqlserver 7.0 to proccess cursor like it did it before. select @var = oldValue declare testCursor cursor for select someColumns from someTable where someColumn = @var select @var = newValue open testCursor fetch next from testCursor into @someColumns Thank's in advance. Mirko.
View Replies !
Stored Procedure Using A Declared Cursor
I need to write a stored procedure using T-SQL to declare a cursor for containing id(staff_no), names and specialism of all doctors that have specialism, The contents of the cursor then are to be displayed using a loop and print statement to give a formatted display of the output of each record within the cursor. The doctors table has the following columns with specialism allowing NULL values doctor ( staff_no CHAR(3), doctor_name CHAR(12), position CHAR(15), specialism CHAR(15), PRIMARY KEY(staff_no) ) Any help would be greatly appreciated.
View Replies !
Schema Name Has Changed In SQL-server 2005!
I am using sql server 2005 express. When I created a new database my schema name was dbo and my stored procedures looks like this: dbo.sp_name Now when I am creating new sp:s my schema name has change to DOMAINUsername: DOMAINUsername.sp_name My webb application cant find any sp:s with this schema name and I don't now how to change schema name back to dbo. What has happened, what is this schema name and why has my schema name been changed!? Please help me out!
View Replies !
How To Handle Schema Changed From Another Server?
Hello, everyone: I have two SQL Servers 2000 in separate machines. In client server, there are some views reading tables from data server. There is a regular running in data server in which some tables are recreated every two weeks. After regular running, there are error message when I run stored procedures in client server, like, Server: Msg 7359, Level 16, State 1, Procedure Validation_Proc, Line 16 The OLE DB provider 'SQLOLEDB' reported a schema version for table '"Data"."dbo"."ALL_Store"' that changed between compilation and execution. OLE DB error trace [Non-interface error: Schema version number changed from compile time (49860953488266905) to run time (49860953488266889) for ProviderName='SQLOLEDB' TableName='"Data"."dbo"."ALL_Store"'.]. The table Data.dbo.ALL_Store is in data server, and stored procedure Validation_Proc is in client server. It looks like schema issue. Any help will be great appreciated. Thanks ZYT
View Replies !
The Cursor Does Not Include The Table ... Error?
We use a lot of virtual machines. I have a base VM with SQL 2005 installed. I rename this VM (i have multiple copies running) and run an old application (VB code, iterates through recordsets, etc.). I get: Microsoft][ODBC SQL Server Driver][SQL Server]Could not find server '2K3VM-DG' in sysservers. Execute sp_addlinkedserver to add the server to sysservers. This makes sense, and I can fix it with sp_dropserver / sp_addserver [local]. Good. The next error is puzzling though: [Microsoft][ODBC SQL Server Driver][SQL Server]The cursor does not include the table being modified or the table is not updatable through the cursor. Any suggestions on how to fix this?
View Replies !
Go And Goto In One Sql Script Gives Error Label Not Declared
Hi,I have a problem:I am writing an update script for a database and want to check for theversion and Goto the wright update script.So I read the version from a table and if it match I want to "GotoVersionxxx"Where Versionxxx: is set in the script with the right update script.Whenever I have some script which need Go commands I get error in theoutput thatA GOTO statement references the label 'Versionxxx' but the label hasnot been declared.But the label is set in the script by 'Versionxxx:'Is there a way I can solve this easily?Thanks in advance
View Replies !
Common Table Expression (CTE) T-SQL Errors:Invalid Object Name 'ProductItemPrices'.The Variablename '@TopEmp' Has Been Declared
Hi all, I copied the following code from a tutorial book and executed it in my SQL Server Management Studio Express (SSMSE): --CET.sql-- USE AdventureWorks GO --Use column value from a table pointed at by a foreign key WITH ProductItemPrices AS ( SELECT ProductID, AVG(LineTotal) 'AvgPrice' FROM Sales.SalesOrderDetail GROUP BY ProductID ) SELECT p.Name, pp.AvgPrice FROM ProductItemPrices pp JOIN Production.Product p ON pp.ProductID = p.ProductID ORDER BY p.Name SELECT * FROM ProductItemPrices GO --Display rows from SalesOrderDetail table with a LineTotal --value greater than the average for all Linetotal values with --the same ProductID value WITH ProductItemPrices AS ( SELECT ProductID, AVG(LineTotal) 'AvgPrice' FROM Sales.SalesOrderDetail GROUP BY ProductID ) SELECT TOP 29 sd.SalesOrderID, sd.ProductID, sd.LineTotal, pp.AvgPrice FROM Sales.SalesOrderDetail sd JOIN ProductItemPrices pp ON pp.ProductID = sd.ProductID WHERE sd.LineTotal > pp.AvgPrice ORDER BY sd.SalesOrderID, sd.ProductID --Return EmployeeID along with first and last name of employees --not reporting to any other employee SELECT e.EmployeeID, c.FirstName, c.LastName JOIN HumanResources.Employee e ON e.ContactID = c.ContactID JOIN HumanResources.EmployeeDepartmentHistory d ON d.EmployeeID = e.EmployeeID JOIN HumanResources.Department dn ON dn.DepartmentID = d.DepartmentID) JOIN Empcte a ON e.ManagerID = a.empid) --Order and display result set from CTE SELECT * Hi all, I copied the following T-SQL code from a tutorial book and executed it in my SQL Server Management Studio Express (SSMSE): --CTE.sql-- USE AdventureWorks GO --Use column value from a table pointed at by a foreign key WITH ProductItemPrices AS ( SELECT ProductID, AVG(LineTotal) 'AvgPrice' FROM Sales.SalesOrderDetail GROUP BY ProductID ) SELECT p.Name, pp.AvgPrice FROM ProductItemPrices pp JOIN Production.Product p ON pp.ProductID = p.ProductID ORDER BY p.Name SELECT * FROM ProductItemPrices GO --Display rows from SalesOrderDetail table with a LineTotal --value greater than the average for all Linetotal values with --the same ProductID value WITH ProductItemPrices AS ( SELECT ProductID, AVG(LineTotal) 'AvgPrice' FROM Sales.SalesOrderDetail GROUP BY ProductID ) SELECT TOP 29 sd.SalesOrderID, sd.ProductID, sd.LineTotal, pp.AvgPrice FROM Sales.SalesOrderDetail sd JOIN ProductItemPrices pp ON pp.ProductID = sd.ProductID WHERE sd.LineTotal > pp.AvgPrice ORDER BY sd.SalesOrderID, sd.ProductID --Return EmployeeID along with first and last name of employees --not reporting to any other employee SELECT e.EmployeeID, c.FirstName, c.LastName FROM HumanResources.Employee e JOIN Person.Contact c ON e.ContactID = c.ContactID where ManagerID IS NULL --Specify top level EmployeeID for direct reports DECLARE @TopEmp as int SET @TopEmp = 109; --Names and departments for direct reports to --EmployeeID = @TopEmp; calculate employee name WITH Empcte(empid, empname, mgrid, dName, lvl) AS ( -- Anchor row SELECT e.EmployeeID, REPLACE(c.FirstName + ' ' + ISNULL(c.MiddleName, '') + ' ' + c.LastName, ' ', ' ') 'Employee name', e.ManagerID, dn.Name, 0 FROM Person.Contact c JOIN HumanResources.Employee e ON e.ContactID = c.ContactID JOIN HumanResources.EmployeeDepartmentHistory d ON d.EmployeeID = e.EmployeeID JOIN HumanResources.Department dn ON dn.DepartmentID = d.DepartmentID WHERE e.EmployeeID = @TopEmp UNION ALL -- Recursive rows SELECT e.EmployeeID, REPLACE(c.FirstName + ' ' + ISNULL(c.MiddleName, '') + ' ' + c.LastName, ' ', ' ') 'Employee name', e.ManagerID, dn.Name, a.lvl+1 FROM (Person.Contact c JOIN HumanResources.Employee e ON e.ContactID = c.ContactID JOIN HumanResources.EmployeeDepartmentHistory d ON d.EmployeeID = e.EmployeeID JOIN HumanResources.Department dn ON dn.DepartmentID = d.DepartmentID) JOIN Empcte a ON e.ManagerID = a.empid) --Order and display result set from CTE SELECT * FROM Empcte WHERE lvl <= 1 ORDER BY lvl, mgrid, empid --Alternate statement using MAXRECURSION; --must position immediately after Empcte to work SELECT * FROM Empcte OPTION (MAXRECURSION 1) ==================================== This is Part 1 (due to the length of input > 50000 characters). Scott Chang
View Replies !
Is It Possible To Use Twice Declared. Variable Names- KILL And After Declared. Variable
is it possible to use twice declared. Variable names- declared. Variable and after KILL and use the same declared. Variable like DECLARE @StartDate datetime KILL @StartDate datetime (remove from memory) use after with the same name i have 2 big stored PROCEDURE i need to put one after one and psss only 1 Variable name to the second stored PROCEDURE like this i don't get this error The variable name '@Start_Date' has already been declared. Variable names must be unique within a query batch or stored procedure. Msg 134, Level 15, State 1, Line 146 The variable name '@End_Date' has already been declared. Variable names must be unique within a query batch or stored procedure. i use like KILL @endDate ?? KILL @StartDate ?? TNX
View Replies !
Join Cursor With Table Outside Of Cursor
part 1 Declare @SQLCMD varchar(5000) DECLARE @DBNAME VARCHAR (5000) DECLARE DBCur CURSOR FOR SELECT U_OB_DB FROM [@OB_TB04_COMPDATA] OPEN DBCur FETCH NEXT FROM DBCur INTO @DBNAME WHILE @@FETCH_STATUS = 0 BEGIN SELECT @SQLCMD = 'SELECT T0.CARDCODE, T0.U_OB_TID AS TRANSID, T0.DOCNUM AS INV_NO, ' + + 'T0.DOCDATE AS INV_DATE, T0.DOCTOTAL AS INV_AMT, T0.U_OB_DONO AS DONO ' + + 'FROM ' + @DBNAME + '.dbo.OINV T0 WHERE T0.U_OB_TID IS NOT NULL' EXEC(@SQLCMD) PRINT @SQLCMD FETCH NEXT FROM DBCur INTO @DBNAME END CLOSE DBCur DEALLOCATE DBCur Part 2 SELECT T4.U_OB_PCOMP AS PARENTCOMP, T0.CARDCODE, T0.CARDNAME, ISNULL(T0.U_OB_TID,'') AS TRANSID, T0.DOCNUM AS SONO, T0.DOCDATE AS SODATE, SUM(T1.QUANTITY) AS SOQTY, T0.DOCTOTAL - T0.TOTALEXPNS AS SO_AMT, T3.DOCNUM AS DONO, T3.DOCDATE AS DO_DATE, SUM(T2.QUANTITY) AS DOQTY, T3.DOCTOTAL - T3.TOTALEXPNS AS DO_AMT INTO #MAIN FROM ORDR T0 JOIN RDR1 T1 ON T0.DOCENTRY = T1.DOCENTRY LEFT JOIN DLN1 T2 ON T1.DOCENTRY = T2.BASEENTRY AND T1.LINENUM = T2.BASELINE AND T2.BASETYPE = T0.OBJTYPE LEFT JOIN ODLN T3 ON T2.DOCENTRY = T3.DOCENTRY LEFT JOIN OCRD T4 ON T0.CARDCODE = T4.CARDCODE WHERE ISNULL(T0.U_OB_TID,0) <> 0 GROUP BY T4.U_OB_PCOMP, T0.CARDCODE,T0.CARDNAME, T0.U_OB_TID, T0.DOCNUM, T0.DOCDATE, T3.DOCNUM, T3.DOCDATE, T0.DOCTOTAL, T3.DOCTOTAL, T3.TOTALEXPNS, T0.TOTALEXPNS my question is, how to join the part 1 n part 2? is there posibility?
View Replies !
Can Table Ownership Be Changed?
When I create tables in SQL I can specify dbo as the owner using thesyntax below but when using the upsize wizard in Access 2000 I owneverything. Is there a way that the system administrator can changeownership after the fact?CREATE TABLE dbo.mytable (c1 int not null)Thank You,Randy KJoin Bytes!
View Replies !
Changed Table Structure
Hi all, How can i get the information as to when was the last my particular table structure was changed (for ex. adding of a column/dropping a column) Pls let me know TIA
View Replies !
How To Put Only Changed Fields Into A New Table
Ha all again. I have this issue: I have 2 tables: t1 (id,field1,field2,field3) and t2 (id,field_name,field_value) is possible with trigger to insert only changed fields on t1 to t2 like (changing field1 on t1 with id 21 cause a new row in t2 with fields id=21,field_name="field1", field_value=field1.value) i hope you understand what i look for. Is this trigger solution ? CREATE TRIGGER MAP_CHANGESON t1AFTER INSERT,UPDATEBEGIN DECLARE @ID SOMEDATA;DECLARE @FIELD1 SOMEDATA;DECLARE @FIELD2 SOMEDATA;DECLARE @FIELD3 SOMEDATA;SET @ID=(SELECT ID FROM INSERTED)SET @FIELD1=(SELECT FIELD1 FROM INSERTED AS T1,DELETED T2 WHERE T1.ID=T2.ID AND T1.FIELD1<>T2.FIELD1)SET @FIELD2=(SELECT FIELD2 FROM INSERTED AS T1,DELETED T2 WHERE T1.ID=T2.ID AND T1.FIELD2<>T2.FIELD2)SET @FIELD3=(SELECT FIELD1 FROM INSERTED AS T1,DELETED T2 WHERE T1.ID=T2.ID AND T1.FIELD3<>T2.FIELD3)IF @FIELD1<>NULL INSERT INTO T2 (ID,FIELD_NAME,FIELD_VALUE) VALUES (@ID,'FIELD1','@FIELD1')IF @FIELD2<>NULL INSERT INTO T2 (ID,FIELD_NAME,FIELD_VALUE) VALUES (@ID,'FIELD2','@FIELD2')IF @FIELD3<>NULL INSERT INTO T2 (ID,FIELD_NAME,FIELD_VALUE) VALUES (@ID,'FIELD1','@FIELD3')RETURNEND
View Replies !
How To Check A Table Whether Data Is Changed Or Not..??
Hi.. I got 10 Tables with data in it for 100 Loans. The data can be Good and Bad ..... I had a Update Proc which Updates the 10 tables with the Good data what ever i pass...for this 100 Loans Tha Proc will update the existing data in all tables whether it is Good or Bad Data. when the updating is completed I want to know what are the Loans that were updated where there is a Bad Data in atleast one Field of the 10tables. I don't want to check field by field in each table.... if there is a bad data and my proc updated with a Good Data i want to know that Loan. Can any one has an idea on this,,,, Thanks Bob
View Replies !
How To Find Out If A Spesific Table Has Changed?
Hi, I have a small question regard how to find out if a specific table has chanced. Is there any (sql)function inside MSSQL2005 that I can use to find if a spesific table has changed? I have heard of timestamp, but I don't know if that will solve my problem? Is there any thing in the sys.tables that kan help me, just do a fast query and check if a table has changed? I'm developing a web-application with AJAX.NET, and I have UpdatePanels with datalist. When the tables in the db gets big the application is henging for a sec or two when it receiving the data, and when the timer (refresh rate) is 2 min it is not good! So my plan is to check if the table has chanced since last transfer of data, and if it has it will download the data, if not do nothing. Jonny
View Replies !
Error - Record Has Been Changed By Another User
I apologize in advance if this has been posted but if you get the attached error "The record has been changed by another user...", we've discovered that this error can occur if you have a SQL Server Data Type of "Float" and also a "Text" Data Type in the same table. We discovered that it only happens on some records though and I am not sure why this is so. The solution is apparently to add a TimeStamp Data Type to the SQL Server table which does seem to fix the problem. If anyone has any insight on any other solutions (we cannot change the Data Types) or the reasoning behind this error, I would greatly appreciate the feedback.
View Replies !
Auditing:Extracting Changed Fields From Inserted Table
Hello,I'm creating an audit table and associated triggers to be able to captureany updates and deletes from various tables in the database. I know how tocapture the records that have been updated or deleted, but is there any waythat I can cycle through a changed record, look at the old vs new values andcapture only the values that have changed?To give you a better idea of what I'm trying to do, instead of creating acopy of the original table (some tables have many fields) and creating awhole record if a type or bit field has been changed, I'd like to onlycapture the change in a single audit table that will have the followingfields;AuditID int INDENTITY(1,1)TableName varchar(100)FieldName varchar(100)OldValue varchar(255)NewValue varchar(255)AuditDate datetime DEFAULT(GetDate())Any direction would be greatly appreciated.Thanks!Rick
View Replies !
Can A Column Data Type Be Changed On A Replicated Table?
On sqlserver 2000 transactional replication: How would I best go about changing a published table's column from smallint to int? I could not find anything about it in BOL or MS.com. I do not think EM/Replication Properties allows the change. I suspect I have to run "Alter Table/Column" on the Publisher and each Subscriber the old-fashioned way. Is that true? Thanks!
View Replies !
Odbc Error - Record Has Been Changed By Another User
The following error is recieved when updating a record using access 97 and odbc driver to an oracle database. This record has been changed by another user since you started editing it. If you save the record, you will overwrite the changes the other user made. Any help is greatly appriciated. Thanks in Advance
View Replies !
Create Target Table Dynamically Based On Source Table Schema?
I’ve got a situation where the columns in a table we’re grabbing from a source database keep changing as we need more information from that database. As new columns are added to the source table, I would like to dynamically look for those new columns and add them to our local database’s schema if new ones exist. We’re dropping and creating our target db table each time right now based on a pre-defined known schema, but what we really want is to drop and recreate it based on a dynamic schema, and then import all of the records from the source table to ours.It looks like a starting point might be EXEC sp_columns_rowset 'tablename' and then creating some kind of dynamic SQL statement based on that. However, I'm hoping someone might have a resource that already handles this that they might be able to steer me towards.Sincerely, Bryan Ax
View Replies !
Tempoary Table Question - How To Create One With The Same Schema As An Existing Table?
Hello, I'd like to create a temporary table with the same schema as an exiting table. How can I do this without hard coding the column definitions into the temporary table definition? I'd like to do something like: CREATE TABLE #tempTable LIKE anotherTable ..instead of... CREATE TABLE #tempTable (id INT PRIMARY KEY, created DATETIME NULL etc... I'm sure there must be a simple way to do this! Many thanks, Ben S
View Replies !
FormView - Update Process Completes With No Error But Records Is Not Changed
Greetings, I have setup a FormView which functions as it should but after the user input is updated, the table record stays unchanged, and when I trap the FormView1_ItemUpdated and look at the SqlDataSource1.UpdateCommand, it shows this: UPDATE [aspnet_test] SET first_name = '', last_name = '', email = '' WHERE id = @original_ID Here is most of the code I am using:<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="id, first_name, last_name" OnItemUpdating="FormView1_ItemUpdating" OnItemUpdated="FormView1_ItemUpdated" > .. // my ItemEditTempate is here.</asp:FormView> <EditItemTemplate>First Name: <asp:TextBox Text='<%# Bind("first_name") %>' runat="server" ID="author_name" Columns="20"></asp:TextBox><br />Last Name: <asp:TextBox Text='<%# Bind("last_name") %>' runat="server" ID="TextBox1" Columns="20"></asp:TextBox><br />E-mail: <asp:TextBox Text='<%# Bind("email") %>' runat="server" ID="TextBox2" Columns="20"></asp:TextBox><br /><br /><asp:Button ID="UpdateButton" runat="server" Text="Update" CommandName="Update" /><asp:Button ID="CancelButton" runat="server" Text="Cancel" CommandName="Cancel" /> </EditItemTemplate> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>" SelectCommand="SELECT id, first_name, last_name, email FROM aspnet_test where id = 1"UpdateCommand="UPDATE [aspnet_test] SET first_name = '<%# first_name %>', last_name = '<%# last_name %>', email = '<%# email %>' WHERE id = @original_ID "> <UpdateParameters><asp:Parameter Name="original_ID" Type="Int32" /></UpdateParameters></asp:SqlDataSource> Any idea where the @original_ID is supposed to get its value from, or why does the SQL command shows blank fields?Thanks Eric.
View Replies !
Altered Table-changed Column From Text To Varchar And Now Having Issues With Alter Switch
Working on partitioning a few large tables. One of the tables included a text column and the €śTEXTIMAGE_ON [PRIMARY]€? clause which would prevent the partitioning of this table. After some research we found that the data was legacy and no longer used. We updated the column on the affected rows to NULLS and altered the column to a VARCHAR(20) When I attempted to run the ALTER TABLE SWITCH I encountered the error Msg 4947, Level 16, State 1, Line 1 ALTER TABLE SWITCH statement failed. There is no identical index in source table 'LocalDeltanet.dbo.testresultsjoe' for the index 'PKIDX_testSummary' in target table 'LocalDeltanet.dbo.testresults_part'. After a lot of grief and testing I determined that the message was bogus and the real issue is that the 'sys.tables' still has €ślob_data_space_id€? with a value of 1 for this table. I created a copy of the table with the text column altered to varchar and one with just the varchar to begin with. After copying data from the original table, I tried to run the alter switch. It failed once again for the text column altered to varchar table, but it worked for the varchar from the start. Since it appears that this value is causing my issues, is there anyway to update the table in place. I know I can BCP the data out, but that would take too long and would defeat the advantage of using the alter switch method. BOL States: The allow updates option is still present in the sp_configure stored procedure, although its functionality is unavailable in Microsoft SQL Server 2005 (the setting has no effect). In SQL Server 2005, direct updates to the system tables are not supported. This means we cannot update the table manually. Thanks
View Replies !
Insert / Update In Master Table And Also Save A History Of Changed Records : Using Data Flow/simple Sql Queries
Hi, My scenario: I have a master securities table which has 7 fields. As a part of the daily process I am uploading flat files into database tables. The flat files contains the master(static) security data as well as the analytics(transaction) data. I need to 1) separate the master (static) data from the flat files, 2) check whether that data is present in the master table, if not then insert that data into the master table 3) If data present then move that existing record to an history table and then update the main master table. All the 7 fields need to be checked to uniquely identify a single record in the master table. How can this be done? Whether we can us a combination of data flow items or write a sql procedure to do all this. Thanks in advance for your help. Regards, $wapnil
View Replies !
Putting Data Into Table B From Table A Without Using A Cursor
on SQL Server 2005, no SP. Currently using a cursor in a stored procedure to retrieve data from one table and to put it into another table. like so: declare @HTR money declare @Uniqueid varchar(15) declare cur_HTR cursor for select uniqueid, sum(hours_to_resolve) as thtr from com_trail_helpdesk_module group by uniqueid open cur_htr fetch next from cur_HTR into @Uniqueid, @HTR while @@fetch_status = 0 begin update com_hpd_helpdesk_history set total_hours_to_resolve = @HTR where case_id_ = @Uniqueid and dateasat = @dateasat fetch next from cur_HTR into @Uniqueid, @HTR end close cur_htr deallocate cur_htr ... This is taking about 45 minutes each time to do 21k records. Is there a faster, better way to do this?
View Replies !
Table Schema
I have a group of TV listing data need to map into database tables.Data looks like following:http://www.oniva.com/upload/1356/crew.jpgI want to create a table for productionCrew of each TV programthe data is like -crew -programID -member-member-member ... etc-programID -member-member-member ... etc-programID -member-member-member ... etc... etcabove are data from productionCrew of all TV program, for eachprogramID we have a list of members.Should I merge all member into a big string?Or should I use 2 tables to store the Crew data?If i use 2 tables, how the fields / column will look like?
View Replies !
Table Schema
Hey, I'm looking at creating a table in a stored procedure [declare @tempTable table] however, rather than then declaring the tables schema [declare @tempTable table (pkField IDENTITY (1,1), SomeOtherField varchar(50), ...)] I'd like it to simply use the schema of an already existing table (plus an additional column). Is there a way to do this without having to manually write the table schema? A simple example is: I have a table OriginalTable (idCol, NameCol, InfoCol) I'd like to create a temp instance of that table called tempTable which would have a final schema of tempTable (idCol, NameCol, InfoCol, myTempCol) The reason I'd like to do this using the schema is so that I don't need to update all my procedures in the future when we decide to add some more detail to the originaltable which needs to be selected as well. Thanks a lot for any help or direction you can provide. -Ashleigh
View Replies !
Getting Table Schema
Hi I come from a MySQL background and have been having some trouble finding the MSSQL command that corresponds to MySQL's "describe." I Googled for around 1/2 hour but can't seem to find it. Any help appreciated
View Replies !
Is This A Valid Table Schema
GO CREATE TABLE [dbo].[CmnLanguage]( [Id] [char](2) NOT NULL CONSTRAINT PkCmnLanguage_Id PRIMARY KEY, [UniqueName] [varchar](26) NOT NULL, [NativeName] [nvarchar](26) NOT NULL, [DirectionType] [smallint] NOT NULL, [IsVisible] [bit] NOT NULL, [CreatedDateTime] [datetime] NOT NULL DEFAULT GETDATE(), [ModifiedDateTime] [datetime] NULL) GO CREATE TABLE [dbo].[CmnLink]( [Id] [int] IDENTITY(1,1) NOT NULL CONSTRAINT PkCmnLink_Id PRIMARY KEY, [UniqueName] [varchar](52) NOT NULL, [IsVisible] [bit] NOT NULL, [CreatedDateTime] [datetime] NOT NULL DEFAULT GETDATE(), [ModifiedDateTime] [datetime] NULL) GO CREATE TABLE [dbo].[CmnLinkCmnLanguage]( [LinkId] [int] NOT NULL CONSTRAINT FkCmnLinkCmnLanguage_LinkId FOREIGN KEY (LinkId) REFERENCES CmnLink(Id) ON DELETE CASCADE, [LanguageId] [char](2) NOT NULL CONSTRAINT FkCmnLinkCmnLanguage_LanguageId FOREIGN KEY (LanguageId) REFERENCES CmnLanguage(Id) ON UPDATE CASCADE ON DELETE CASCADE, [CreatedDateTime] [datetime] NOT NULL DEFAULT GETDATE(), [ModifiedDateTime] [datetime] NULL)
View Replies !
Create Table From XML Or XML Schema?
Is it possible to create tables using XML or a predefined XML Schema?I have a large data specification which includes it's XML schema. Iwanted to use the schema to generate the tables that eventually willbe populated and used to output the final XML document.
View Replies !
Large Table Schema Changes
Quick question:Does SQL do table/schema changes "in place"?I've got a large table (140+ million rows of very widedata) that we want to change the schema on -- basicallyto remove a number of the unused data elements that wedon't use.Anyway, does anyone know if SQL will do an in-placechange, or if it will copy the table to a new table, therebyincreasing my space allocation needs? I'd effectively,temporarily, need space for two tables while the changeis happening if it copies the table first. This is not good asI do not have enough available space at the moment.If you've got pointers to specific MS docs regardingthis issue, please let me have 'em.Thanks in advance.
View Replies !
Creating Table With Different SCHEMA...
Hi all, i m using sql server2005 CTP...i created a database called TEL and in that database i created a user(in security) as USE [TEL] GO /****** Object: User [COLL_DB] Script Date: 09/27/2005 15:38:51 ******/ GO CREATE USER [COLL_DB] FOR LOGIN [loginName] WITH DEFAULT_SCHEMA=[COLL_DB] Now,when i m trying to create a table in the database TEL as CREATE TABLE [COLL_DB].abc (c numeric) commit; it gives me error saying The specified schema name "COLL_DB" either does not exist or you do not have permission to use it. Now,can someone tell me...what i have to do to fix this error????????? thanks...
View Replies !
Alter Schema Of A Table
I have a problem, in one of my db's I have a table tblpersons in schema web the rest of the table's in the db are in schema dbo. Now I removed the user web, but I want to change the schema of tblpersons from web.tblpersons to dbo.tblpersons. I created a stored procedure with the line " ALTER SCHEMA dbo TRANSFER web.tblpersons", when executing this I get an error that the table tblpersons couldn't be found.
View Replies !
Table Script Or Schema
Hi, acutally i am looking to get the script of table that is already in the database, like there is a table INFORMATION_SCHEMA.ROUTINES WHERE routine_type = 'PROCEDURE' which return us the routine defination of the procedure. is there anything similar for table ? i know i can just right clike on table and create a script but i don't use this method. Thanks and looking forward.-MALIK
View Replies !
Edit Table Schema
I need to edit a column (PK - GUID) from "Row is GUID = False) to (Row is GUID = True). I get a DLL internal error. I hate to drop the table & recreate from scratch...wish you could edit in SSMSE. Also, I used sync services to create the SDF, you would think that it would be the same as the MDF (just a gripe...sorry ) VB 2008 SQL 2005 Express SSMSE SP2 Thanks, Vareck
View Replies !
Table Schema Problem!!
Hi, I am a bit confused and wish to share this with you for help. We are designing a billing application to bill telephone calls. It currently handles a single rate plan. So what it does is that it looks up the RATES table and matches the called number area code with the RATES.ACCESS_Code field to find the tariff for that area and multiplies that by the number of minutes. Here is the current schema. CALLS •ID (pkid) •Called Number •Duration RATES •Destination Name •Access_Code (pkid) •Tariff Now the problem is that we need to process calls based on RATES per OPERATOR. Each operator is a telephony carrier with similar RATES. However, each call will be prefixed with a number to indicate which operator carried that call. Accordingly, the database should relate that prefix with the proper operator and then looks up the RATES that are related to that operator. In conclusion we will have a replica of the RATES table for multiple operators. An operator is only supposed to have two fields I guess (name and ID). So now we need to re-engineer the schema to adapt to this situation. Eg. 95004433313445 (Will be identified as BT operator) 93004422376234 (Will be identified as AT&T operator) Can anyone help please? PS: we are using SQL Express 2005 Thanks
View Replies !
Table Name And Cursor
I am using MS-SQL Server 2K.... I have a stored procedure that contains a cursor. Right now, the table name for the cursor is "hard-coded". I would like to be able to "soft-code" the table name, because the table name may vary (although the fields would always be the same). Is this even possible? The only workaround I can think of is to use an EXEC on a real-time built SQL statement into a temp table and then cursor through the temp table. Is there a better way to do this? Thanks...
View Replies !
Dbo Schema Added When I Rename Table
i recorded a script for a change i need to make. actually 15 so far, i am getting ready to bring an access db with no pk or fk and only 1 relation over to ss05 my scripts are used to add the need pk fk to the tables and then move the data from the temptbl to the new one 1 thing i have been noticing is code like below will rename the table dbo.aMgmt.Employee and with that all the remaing lines of the script will fail. DROP TABLE aMgmt.Employee GO EXECUTE sp_rename N'dbo.Tmp_Employee', N'aMgmt.Employee', 'OBJECT' GO any help?
View Replies !
|