I have an cursor that loops 720 times.
Each FETCH does 6 INSERTS.
Each FETCH the 6 INSERTs a total of 200-300 records appended.
Would explicit transactions speed up the cursor?
In Oracle, I would keep track of how many times I've looped, and commit every nth time. I would put a catch remainder COMMIT at the end of the procedure.
I've got the IF @@TRANCOUNT > 19 COMMIT TRAN (about 6k records), but say I had <= 19 remaining at the end of the cursor, how do you get those to commit? I tried to put an IF @@TRANCOUNT > 1 COMMIT TRAN, but that didn't work.
What's a good @@TRANCOUNT to commit at in this case?
I€™m using triggers for some more advanced integrity check. The problems is that the same trigger can be run from explicit transaction (this is when I start transaction from .NET) and as autocommit transaction ( very rare, only when we do some maintenance directly with SQL statements).
Currently if I want to rollback transaction from trigger I only issue RAISERROR statements, then .NET application catches this error and generates rollback. But the problem is if trigger is raised from some SQL statements outside .NET application (normally some maintenance work direct from SQL manager ) in that case error is generated but there is no rollback.
Is there any way to distinguish if transaction in trigger is explicit or autocommited, because for autocommited transaction I also need use ROLLBACK TRANSACTION?
When I need to perform an update against multi-million row table Itypically specify @@rowcount, to reduce locks.e.g.set @@rowcount 1000while exists (select * from myTable where col2 is null)update myTableset col2 = col1 + 'blahblah'where col2 is nullHowever, my boss' script does something like this. I think it works OKbut it seems overly complicated to me. Any thoughts?while exists (....)begin traninsert into #tableselect ...update myTableset ...from myTable join #table ...(@numberOfRows is a counter variable, tracking #rows that have beenupdated since last batch)if @numberOfRows > 1000begincommitbegin tranendend
Hi there, I have decided to move all my transaction handling from asp.net to stored procedures in a SQL Server 2000 database. I know the database is capable of rolling back the transactions just like myTransaction.Rollback() in asp.net. But what about exceptions? In asp.net, I am used to doing the following: <code>Try 'execute commands myTransaction.Commit()Catch ex As Exception Response.Write(ex.Message) myTransaction.Rollback()End Try</code>Will the database inform me of any exceptions (and their messages)? Do I need to put anything explicit in my stored procedure other than rollback transaction? Any help is greatly appreciated
i have a situation, where i need to group my information by a certainid, but that information which should already be grouped, i need toorder based on a number in one of the columnsexample:<ex id=2 listorder=1><description>desc 2</description></ex><ex id=1 listorder=2><description>desc 1</description></ex>in my order clause i first put order by the id, and it will group theinformation accordingly, but will put the lowest number id first, notcaring about the listorderbut if i order by the listorder column first, the information isn'tgroupd properlyi don't know if i made myself clear enough?hope someboyd can help methnx in advance
I don't know MS-SQLserver internal system at all. I 've just used Oracle a couple years ago and so in some cases (e.g using TP-monitor MTS or Tuxedo) you can switch off the implicit transaction by using the option AUTOCOMMIT ON/OFF.
How can switch off the implicit transaction system on MS-SQLServer ?
I created a SELECT statement that uses the FOR XML EXPLICIT clause so that SQL Server data can be exported to another system. Format thios system accepts is XML. What should I define within a DTS package so that this Select statement is executed and an XML file is created?
In the SP below, I get the following error when I run it: Explicit value must be specified for identity column in table 'Tests' when IDENTITY_INSERT is set to ON.
From what I've read of the INSERT method, it says you can add a variable value. So I don;t understand why it won't take mine.
CREATE PROC qaspAddTestRecord AS
DECLARE @aKey bigint DECLARE @aTestSuiteId bigint
exec qaspGetNewID 'Tests', @aKey OUT
SELECT @aTestSuiteId= NewID FROM ID WHERE TableName='TestSuite'
SET IDENTITY_INSERT Tests ON
INSERT INTO Tests (TestSuiteId, TestIDInternal) VALUES (@aTestSuiteId, @aKey)
Hello all,I'm trying to generate some XML directly from MS SQL with thefollowing codeSELECT1 AS tag, NULL AS parent, NULL AS [GoogleCustomizations!1], NULL AS [Annotations!2], NULL AS [Annotation!3], NULL AS [Annotation!3!about], NULL AS [Annotation!3!score], NULL AS [Label!4], NULL AS [Label!4!name]UNIONSELECT2 AS tag, 1 AS parent, NULL, NULL, NULL, NULL, NULL, NULL, NULLUNIONSELECTTOP 503 AS tag, 2 AS parent, NULL, NULL, NULL, 'www.' + domainName, 1 -- score, NULL, NULLFROM tbl_auDomainNameUNIONSELECT4 AS tag, 3 AS parent, NULL, NULL, NULL, NULL, NULL, NULL, '_cse_ad-o6lgdody'FOR XML EXPLICITThe XML it needs to create is as following<GoogleCustomizations><Annotations><Annotation about="www.clickfind.com.au/*" score="1"><Label name="_cse_ad-o6lgdody" /></Annotation><Annotation about="www.lookle.com/*" score="1"><Label name="_cse_ad-o6lgdody" /></Annotation><Annotation about="www.sensis.com.au/*" score="1"><Label name="_cse_ad-o6lgdody" /></Annotation></Annotations></GoogleCustomizations>It is currently creating<GoogleCustomizations><Annotations><Annotation about="www.10000steps.org.au" score="1" /><Annotation about="www.101fm.asn.au" score="1" /><Annotation about="www.aao.gov.au" score="1"><Label name="_cse_ad-o6lgdody" /></Annotation></Annotations></GoogleCustomizations>I cannot get my head around how I can get the label <Labelname="_cse_ad-o6lgdody" />in each element. Does anyone know?Thanks in advance.
HiI have to create an XML file based on a SQL SERVER 2005 table.Everything works fine:SELECT 1 as Tag, NULL as Parent, Ex_Id as [Exam!1!Ex_Id], NULL as [Ex_Title!2!!cdata] FROM Exams WHERE ex_State = 'P' UNION ALL SELECT 2 as Tag, 1 as Parent, Ex_Id, ex_Title FROM Exams WHERE ex_State = 'P' order by [Exam!1!Ex_Id], [Ex_Title!2!!cdata] FOR XML EXPLICIT, ROOT('Exams') BUT when i add another column, a text column, I get into trouble: SELECT 1 as Tag, NULL as Parent, Ex_Id as [Exam!1!Ex_Id], NULL as [Ex_Title!2!!cdata], NULL as [Ex_Situation!3!!cdata] FROM Exams WHERE ex_State = 'P' UNION ALL SELECT 2 as Tag, 1 as Parent, Ex_Id, ex_Title, ex_Situation FROM Exams WHERE ex_State = 'P' order by [Exam!1!Ex_Id], [Ex_Title!2!!cdata], [Ex_Situation!3!!cdata] FOR XML EXPLICIT, ROOT('Exams') The problem is clearly the fact that i have to sort on the text column, plus the fact that this column requires the CDATA tag enclosurePlease help me....i'm desperate :(
I am developing an integration process between two databases. One ofthem is a SQL Server 2000 and the other is using MSDE 2000. Theintegration process is done in C# (VS2003).The main database is the SQL Server, the MSDE will contain a reallysmall subset of the data found on the main. To help diminish the amountof time taken to develop an integration process between thosedatabases, the same structure are found on both side. The onlydifference, when I insert data in the MSDE from the SQL Server, I setthe IDENTITY_INSERT to ON and use the same IDs found on the SQL Server.I can insert one set of data without problem, but from there, if I tryagain, I will always receive the "Cannot insert explicit value foridentity column in table ... when IDENTITY_INSERT is set to OFF." Isaw on Microsoft website the article ID 878501; I noticed I was usingMSDE sp3, I upgraded to SP4... and I still have the problem.I know, when I call the update function on the sqldataadapter, theadapters contain the IDENTITY_INSERT ON and it's set to OFF after theinsert. The "Cannot insert..." error is the only one I received.Can anyone help me on that issue? Take note that this approach wasused because of customer requirements; the size of the database alsocauses some problem (over 200 tables) and we decided to use the samestructure on both side to minimize the support time.
I'm using SQL Server Express 2005, with mixed authentication mode. I would like to connect, manipulate data and administrate db's on my server without explicit permissions on those db's. I've created a new Login with SQL Server authentication and assigned it the public & sysadmin server roles BUT I can't even connect to db's where I don't have an explicit db role (db_owner, ddl_admin...)! What am I missing? How can I administrate a db without explicit permissions (db role) on that db?
for some unknow reasons.. my store proc stop working.. and i got an error.. i have installaed the latest SP4 for SQL server 2000 and still have the problem !any ideas why ?? Message "An explicit value for the identity column in table 'LCMS_Modules' can only be specified when a column list is used and IDENTITY_INSERT is ON."CREATE procedure LCMS_Modules_Add @PageID int, @ModuleDefID int, @Panename nvarchar(32), @Title nvarchar(128), @Admins nvarchar(256) as insert into LCMS_Modulesvalues(@PageID, @ModuleDefID, 99, @Panename, @Title, '0;', @Admins, 0, '', 'Center', '', '', '', 1, 0)GO
I have a DTS that pulls a file from a networked drive (generally using the u: designation) for part of its process. Recently, the server has been dropping network drive connections, so sometimes the DTS will fail (I'm not certain why it's dropping the connections, nor do I have the access or control to figure out such.)
I've been told that I should change the DTS package to use an explicit path (i.e., \serverfolder1folder2file.mdb instead of u:folder2file.mdb) to work around this problem. However, Enterprise Manager doesn't seem to like using this for the "File name" attribute in the connection properties. (This is an Access connection, if that matters.)
Is there any way to get the explicit path (probably the wrong terminology here) to work with the connection properties?
I'm attempting to use FOR XML EXPLICIT in SQLServer to adhere to the following template: <group> <sourceid> <source></source> <id></id> <grouptype> <scheme></scheme> <typevalue></typevalue> </grouptype> <description> <short></short> <long></long> </descrption> </group>
Here's my code: SELECT 1 as Tag, NULL as Parent, @p_school_desc as [sourceid!1!source!element], @p_term_code as [sourceid!1!id!element], NULL as [grouptype!1!scheme!element], NULL as [grouptype!1!typevalue!element], NULL as [description!1!short!element], NULL as [description!1!long!element] FROM course_main AS sourceid where sourceid.course_id = @p_course UNION SELECT 1 as Tag, NULL as Parent, NULL, NULL, @p_destination as [grouptype!2!scheme!element], 'Term' as [grouptype!2!typevalue!element], NULL, NULL FROM course_main AS grouptype where grouptype.course_id = @p_course UNION SELECT 1 as Tag, NULL as Parent, NULL, NULL, NULL, NULL, @p_term_code as [description!2!short!element], @p_term_description as [description!2!long!element] FROM course_main AS grouptype where grouptype.course_id = @p_course FOR XML EXPLICIT
I'm receiving the foollowing error: Server: Msg 6812, Level 16, State 1, Line 14 XML tag ID 1 that was originally declared as 'sourceid' is being redeclared as 'grouptype'. Is there anyway to have two different child notes off of the same parent node?
I'm attempting to use FOR XML EXPLICIT in SQLServer to adhere to the following template: <group> <sourceid> <source></source> <id></id> <grouptype> <scheme></scheme> <typevalue></typevalue> </grouptype> <description> <short></short> <long></long> </descrption> </group>
Here's my code: SELECT 1 as Tag, NULL as Parent, @p_school_descas [sourceid!1!source!element], @p_term_code as [sourceid!1!id!element], NULLas [grouptype!1!scheme!element], NULLas [grouptype!1!typevalue!element], NULLas [description!1!short!element], NULLas [description!1!long!element] FROM course_main AS sourceid where sourceid.course_id = @p_course UNION SELECT 1 as Tag, NULL as Parent, NULL, NULL, @p_destinationas [grouptype!2!scheme!element], 'Term' as [grouptype!2!typevalue!element], NULL, NULL FROM course_main AS grouptype where grouptype.course_id = @p_course UNION SELECT 1 as Tag, NULL as Parent, NULL, NULL, NULL, NULL, @p_term_codeas [description!2!short!element], @p_term_descriptionas [description!2!long!element] FROM course_main AS grouptype where grouptype.course_id = @p_course FOR XML EXPLICIT
I'm receiving the foollowing error:Server: Msg 6812, Level 16, State 1, Line 14 XML tag ID 1 that was originally declared as 'sourceid' is being redeclared as 'grouptype'.
Is there anyway to have two different child notes off of the same parent node?
Hi, Is it possible to format any kind of XML file with the FOR XML EXPLICIT mode in SQL Server 2005? I am asking because I am trying to format my file in a way that I could get 2 or 3 elements on my parent or child level and put some attributes (icon path for example) in these 2nd element or 3rd element. I am unable to format it that way. Let me show you the way that I would like to have my XML file formated :
I want to have all my parent, children, sub-children to have these attribut but I am having difficulty putting one in the “Cell” tags. And I really think that my problem resides in the specifying of my column and their directives but I do not know how to fix it. See my icon path is commented here. I have to put the [row!2!cell!xmltext], but it is not working.
Here is the way that I am building my Select query.
SELECT 1 as tag, NULL as parent, NULL AS 'rows!1!', ----Root rows tag ID_metric as [row!2!id], Description_english as [row!2!cell!Element], ----Icon as [row!2!cell!xmltext], Sort as [row!2!sort], ID_metric as [row!3!id], Description_english as [row!3!cell!Element], --Icon as [row!3!cell!xmltext], sort as [row!3!sort], ID_metric as [row!4!id], Description_english as [row!4!cell!Element], --Icon as [row!4!cell!xmltext], sort as [row!4!sort], ID_metric as [row!5!id], Description_english as [row!5!cell!Element], --Icon as [row!5!cell!xmltext], sort as [row!5!sort], FROM #buildData WHERE HLevel = 0 UNION ALL SELECT 2 as tag, 1 as parent, NULL AS 'rows!1!', ID_metric as [row!2!id], Description_english as [row!2!cell!Element], --Icon as [row!2!cell!xmltext], sort as [row!2!sort], ID_metric as [row!3!id], Description_english as [row!3!cell!Element], --Icon as [row!3!cell!xmltext], sort as [row!3!sort], ID_metric as [row!4!id], Description_english as [row!4!cell!Element], --Icon as [row!4!cell!xmltext], sort as [row!4!sort], ID_metric as [row!5!id], Description_english as [row!5!cell!Element], --Icon as [row!5!cell!xmltext], sort as [row!5!sort], FROM #buildData WHERE HLevel = 1 UNION ALL SELECT 3 as tag, 2 as parent, NULL AS 'rows!1!', ID_metric as [row!2!id], Description_english as [row!2!cell!Element], --Icon as [row!2!cell!xmltext], sort as [row!2!sort], ID_metric as [row!3!id], Description_english as [row!3!cell!Element], --Icon as [row!3!cell!xmltext], sort as [row!3!sort], ID_metric as [row!4!id], Description_english as [row!4!cell!Element], --Icon as [row!4!cell!xmltext], sort as [row!4!sort], ID_metric as [row!5!id], Description_english as [row!5!cell!Element], --Icon as [row!5!cell!xmltext], sort as [row!5!sort], FROM #buildData WHERE HLevel = 2 UNION ALL SELECT 4 as tag, 3 as parent, NULL AS 'rows!1!', ID_metric as [row!2!id], Description_english as [row!2!cell!Element], --Icon as [row!2!cell!xmltext], sort as [row!2!sort], ID_metric as [row!3!id], Description_english as [row!3!cell!Element], --Icon as [row!3!cell!xmltext], sort as [row!3!sort], ID_metric as [row!4!id], Description_english as [row!4!cell!Element], --Icon as [row!4!cell!xmltext], sort as [row!4!sort], ID_metric as [row!5!id], Description_english as [row!5!cell!Element], --Icon as [row!5!cell!xml], sort as [row!5!sort], FROM #buildData WHERE HLevel = 3 ORDER BY [row!2!sort], [row!3!sort], [row!4!sort], [row!5!sort] for XML explicit
The FOR XML clause is invalid in views, inline functions, derived tables, and subqueries when they contain a set operator. To work around, wrap the SELECT containing a set operator using derived table syntax and apply FOR XML on top of it.
I have tried a couple of other ways but continue to get an error message.
I am trying to insert a new record into a sql table and I get the following error message:
Msg 544, Level 16, State 1, Line 1 Cannot insert explicit value for identity column in table 'tbl_MLS_ReportCriteria' when IDENTITY_INSERT is set to OFF.
Is there any difference between explicit inner join and implicitinner joinExample of an explicit inner join:SELECT *FROM employeeINNER JOIN departmentON employee.DepartmentID = department.DepartmentIDExample of an implicit inner join:SELECT *FROM employee, departmentWHERE employee.DepartmentID = department.DepartmentID
I gave a developer rights to the Public role on a SQL Server 2000 database. The Public role only has explicitly set select rights to the system tables and one user table. There are no other explicit rights set. The developer was able to open a table that had no rights set in enterprise manager and change data. Is this possible?
Hi, I am trying to create a XML out of sql 2005 database using FOR XML. I need to create XML for tables which may contain data having non-printable ascii characters (1-32 ascii character). I found FOR XML AUTO failes to genrate this XML, but i can genrate XML using CDATA section in FOR XML EXPLICIT. As following querie works fine for me.
SELECT 1 AS tag NULL AS parent, template_id AS [Emailqueue!1!user_id], misc1 AS [Emailqueue!1!!cdata] FROM Emailqueue WITH (NOLOCK) WHERE queue_id = -2147483169 FOR XML EXPLICIT
in above query misc1 column may contain some non printable ascii characters.
But i need to store this XML data in some sql XML variable as i need to pass it to store procedure which expects an xml input. While doing following i gets an error saying "illegal xml character"
DECLARE @XMLMessage XML
SET @XMLMessage = (SELECT 1 AS tag NULL AS parent, template_id AS [Emailqueue!1!user_id], misc1 AS [Emailqueue!1!!cdata] FROM Emailqueue WITH (NOLOCK) WHERE queue_id = -2147483169 FOR XML EXPLICIT)
I am doing all this exercise for SQL service broker. For which i even need to process same message using OPENXML on differen database server. Again which will need well formated XML.
Hi there, I was wondering if someone could propose a solution for the following scenario:
TimeID column would have values from 1 to 6 and rows will be inserted only for those timeIDs where we have Data value as well. While retrieving data we would like to have all timeID range returned with explicitly specifying NULL for missing Data column. Please see below to better understand the situation.
I have a table called Appointment, for storing (you guessed it) appointments at a medical practice. If an appointment is cancelled, I want to collect a cancellation reason, so let's say that I create a second table called Cancellation which has a foreign key relating to the Appointment table's primary key, AppointmentID, and another column, Reason. Now, in order to indicate that an appointment was cancelled, I could include a Cancelled column in the Appointment table with a bit datatype, or instead I could infer that an appointment must be cancelled if it has a corresponding record in the Cancellation table.
It may be that it'd be better to store the cancellation reason in the Appointment table - But regardless, let's say I stick with the two-table solution described above, and I subsequently want to write a query to list all appointments which have been cancelled. If I had the Cancelled column in the Appointment table, I could simply query for all records in that table where that column's value was FALSE. If I went the other way and DIDN'T have a Cancelled column, I could instead write a query joining the Appointment and Cancellation tables to return all records in Appointment with a corresponding record in Cancellation.
That latter method, whilst slightly more complicated because it involves joining two tables, seems to me to be the most normalised. Instead of storing the fact that an appointment is cancelled in two different tables, that fact is only stored in the Cancellation table. Would there be a performance hit in using the two-table, 'inferred cancellation' method rather than just having a bit column in the Appointment table? Would that performance hit be enough to persuade you to use a Cancellation column in the Appointment table instead? And what about if I were to apply that method to other things associated with each appointment, e.g. Is it completed? Is it chargeable to the client or an insurance company? Is the client and in-patient or out-patient?