Quantcast
Channel: SQL Server Database Engine forum
Viewing all 12963 articles
Browse latest View live

Running Total Variation Query Time Optimization

$
0
0

Hi all, 

I've been struggling with this query for a while. I need to set a customer specific running total for 10 million rows (reset for every customer). But every time the number goes negative, I need to set it as zero.

For example,

member no              amount            wallet

member1                 400                      400

member1                 -500                     0

member1                  200                    200

member2                  700                    700

member2                 -200                    500

Query:

DECLARE @member float
DECLARE @prev_member float
DECLARE @amount float
DECLARE @wallet float

DECLARE db_cursor CURSOR FOR  
SELECT [Member no], [Transaction Amount] 
FROM [wallet_master_3]
ORDER BY [Member No], [rownum]
FOR UPDATE

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @member, @amount

SET @prev_member = @member
set @wallet=0

WHILE @@FETCH_STATUS = 0
BEGIN   
       IF @prev_member <> @member set @wallet=0

       SET @wallet = @wallet + @amount

       IF @wallet < 0 SET @wallet = 0

       UPDATE [wallet_master_3] SET walletsize = @wallet
       WHERE CURRENT OF db_cursor

       set @prev_member=@member

       FETCH NEXT FROM db_cursor INTO @member, @amount
END   

CLOSE db_cursor   
DEALLOCATE db_cursor

I've tried using a cursor. In five minutes, it ran 17,000 rows but after running it for 15 hours, the code only manages to set the running total for 175,000 rows. I'm not exactly sure why. Is there a faster approach I can use? 

Thanks!


SQL Server Agent Stopped

$
0
0

Received an error in SQL Server Agent and none of the Job executed as per schedules and attaching a screen shot of the Error Message while expanding the Job Folder under SQL Server Agent. Additionally, need to find the RCA for this issue to avoid the re-occurrence. Pls share your experience if any such issue which you have faced earlier.

As usual, after re-starting the Windows Server the issue got fixed and no RCA captured. Please let me know how to drill down and find out the RCA for this issue.

oledb or .net providers

$
0
0

Hi we run 2012 std.  I learned recently that our ssis pkgs and some of the proxy clients they call r using different sql providers.

I learned by accident because the conn strings used in ssis didn't work in the proxies and vice versa.  So now, when we pass the proxy a conn string 4 the same db, we need an extra config entry with the different format.

If I can talk our folks into consistency, which is a better performer oledb (used by our ssis off the shelf components currently) or .net provider?  r there other advantages and disadvantages beside performance?  The ssis forum was able to take the question pretty far but this last point seems better suited to the engine forum.

Partition elimination inconsistent behavior

$
0
0

Hello.

When we query a partitioned table and partition-aligned indexes are employed, seeks are performed in two steps: If the partition column is used as a predicate, the index is used to eliminate partitions assigned to ranges the predicate values don't fall in. Then it proceeds to perform serial scans/seeks in any remaining partitions.

Now suppose I have a table partitioned on a varchar(10) column. Ranges are defined for values '230' and '281'. In SQL Server 2012 SP1,partition elimination won't happen unless i explicitly convert the predicate value to varchar(10).

NOTE: I'd like to refrain from posting the scripts to generate the entire data structure because they are sensitive.

Basically the original objects are like the ones below:

CREATE TABLE TEST
(PARTITION_COLUMN VARCHAR(10),
SOME_ID INT)
GO
CREATE CLUSTERED INDEX IDX_TEST (PARTITION_COLUMN, SOME_ID) ON PARTITION_SCHEME(PARTITION_COLUMN)
GO
CREATE VIEW VW_TEST AS
SELECT SOME_ID, PARTITION_COLUMN
FROM TEST
WHERE SOME_ID = 9
GO

Partition scheme has 3 filegroups to cover the ranges '230' and '281' in the partition function. The partition function expects a varchar parameter.

CREATE PARTITION FUNCTION [RANGE_PROJETOS](varchar(10)) AS RANGE LEFT FOR VALUES (N'230', N'281')
GO

When I use a literal varchar value:

SELECT COUNT(*) FROM VW_TEST
WHERE PARTITION_COLUMN = '234'

Seek Keys[1] tell us there is no partition elimination, since its filter implies the selection of all partitions. If I later run this query, the "Actual partition count" value will be 3.

If I either use a variable or explicitly convert the literal value to varchar(10), partition elimination will be done:

However, the plan behavior is still inconsistent. The "RangePartitionNew" function is used when the literal value isn't known at compile time, which is acceptable for the query to the left, in the image above, because a variable is being used, but not for the query to the right. What makes the latter all the more strange is the fact that it does an implicit conversion to varchar(10) even though it is already explicitly converted to the very same data type!!


Is there a way to get SQL Agent jobs to COMPLETE before moving on to the next step?

$
0
0
I Have a Pre-Nightly-Process that is comprised of 5 steps in a SQL agent job. Is there a way to stop the agent from moving on to the next step until the current task is completed? I know that on the advanced tab you can tell the task to move on to the next step upon success but that is not what we need. I have seen a couple of post that modified the sp_start_job stored procedure to loop until the job status changes, but I was hoping to avoid modifying a stored procedure. Any help would be appreciated.

FTS Question: When does FT CRAWL / FT CRAWL MON come into play and what are their functions?

$
0
0

 Each week we have a maintenance job that refreshes data in a table containing an FTS-indexed column. This table exists solely for FTS use and is therefore not a user table. It is updated real-time via CDC and set to CT update for near real-time searching.

Everything appears to work reasonably well. When we run the maintenance job however we have experienced blocking and locking issues, leading to deadlocks, which primarily indicate an issue on the index. When reviewing SP_Who I can see that FT CRAWL is a blocker.

I have re-written the job steps to negate this by using a staging table, and noticed  that FT CRAWL does not appear to come into play until after the Insert is completed. 

My question is what is the primary purpose of FT CRAWL & FT CRAWL MON. My (uneducated) thoughts were it was the actual Indexing process that built the tokens index, but I have been unable to find a reliable resource to fully explain it. "SQL2012 Unleashed" comes close, but still not explicit enough.

Any assistance would be greatly appreciated for this relative newbie, thanks in advance


Msg 1088, Level 16, State 9, Line 1 Cannot find the object "sys.syscommittab" because it does not exist or you do not have permissions.

$
0
0

When I am rebuilding indexes/defrag on our production database. SQL serve is throwing below error. It's SQL Server 2008 EE. 

Any idea what could be causing this error?

Msg 1088, Level 16, State 9, Line 1

Cannot find the object "sys.syscommittab" because it does not exist or you do not have permissions.

Thanks,

Sree

ring_buffer output NetworkReadsInMilliseconds shows high read.

$
0
0
Hi, 
can someone help me understand the following ring buffer output? is says 
<NetworkReadsInMilliseconds>97727</NetworkReadsInMilliseconds> and the client call originated from 'local machine'. Why does it takes network path when the client process and sql server is in same box? what should i do to reduce networkReadsInMilliseconds value? 
 
 
<Record id="535" type="RING_BUFFER_CONNECTIVITY" time="203270543"><ConnectivityTraceRecord>
<RecordType>LoginTimers</RecordType><Spid>0</Spid>
<SniConnectionId>9D7C00AB-693A-45CF-B596-C67E1D41D38F</SniConnectionId>
<SniConsumerError>17830</SniConsumerError>
<SniProvider>4</SniProvider><State>103</State>
<RemoteHost>&lt;local machine&gt;</RemoteHost>
<RemotePort>0</RemotePort><LocalHost />
<LocalPort>0</LocalPort><RecordTime>8/10/2011 4:57:30.310</RecordTime><TdsBuffersInformation>
<TdsInputBufferError>0</TdsInputBufferError>
<TdsOutputBufferError>0</TdsOutputBufferError>
<TdsInputBufferBytes>340</TdsInputBufferBytes>
</TdsBuffersInformation><LoginTimers>
<TotalLoginTimeInMilliseconds>97729</TotalLoginTimeInMilliseconds>
<LoginTaskEnqueuedInMilliseconds>0</LoginTaskEnqueuedInMilliseconds>
<NetworkWritesInMilliseconds>0</NetworkWritesInMilliseconds>
<NetworkReadsInMilliseconds>97727</NetworkReadsInMilliseconds>
<SslProcessingInMilliseconds>16</SslProcessingInMilliseconds>
<SspiProcessingInMilliseconds>0</SspiProcessingInMilliseconds>
<LoginTriggerAndResourceGovernorProcessingInMilliseconds>0</LoginTriggerAndResourceGovernorProcessingInMilliseconds>
</LoginTimers></ConnectivityTraceRecord>

SQL Server Connectivity Issue

$
0
0
I am able to connect the server but not to the SSMS. getting the below error:

"
The client was unable to establish a connection because of an error during connection initialization process before login. Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; the server was too busy to accept new connections; or there was a resource limitation (insufficient memory or maximum allowed connections) on the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) (Microsoft SQL Server, Error: 10054)"

To fix it :
I have done some changes in system registry..

from the path... \System\CurrentControlSet\Control\Lsa\Kerberos\Parameters
-- Added the following registry value:
Name: MaxTokenSize
Data type: REG_DWORD
Radix: Decimal
Value: 48000
--Rebooted server

and it resolves the issue for me..

BUT it is happening weekly basis..
and every time server restart resolves the issue.

CAN ANYBODY HELP TO FIX THE ISSUE PERMANENTLY..


Details :
SQL Server 2005 -- SP4 -- Standard Edition (64-bit)
MS Windows Server 2003 R2 -- SP2-- Standard x64 Edition
RAM: 16 GB

Thanks in advance...

Question about database mirroring

$
0
0
Hi,
With SQL Server database mirroring, do you know if SQL Server validate changes before they are applied to the mirror database ?
If I have a corrupt san lun on my primary database, I assume than database mirroring will not transfert it to the mirror database located on another san lun ?


Because in Oracle, they have that:

Oracle Data Guard is the Oracle MAA recommended data availability solution, and it is the
best solution for protecting against data loss, corruptions, and lost writes.
Data Guard maintains a copy of your data in a standby database that is continuously updated
with changes from the production database. Data Guard validates all changes before they are
applied to the standby database, preventing physical corruptions that occur in the storage layer
from causing data loss and downtime.

regards

SQL connectivity problem

$
0
0

Hi to all,

 

Can anybody resolve this eror i.e.

 

Provider: named pipes Provider, error- 40 could not open the connection to the SQL Server.

 

i have done a lot of search to resolve it but i could nt get a exact solution of this problem.Please it s humbly requested to you people please give me the solution of as soon as possible. Actually  i m doing my final project  in C#>NET with using SQL SERVER 2005 and have a very hsort time to complete the project but due to this problem i cannot go forward.Please reply me as soon as possible.

 

I m waiting for your response

Thanks in advance

 

meerab

Unable to connect to remote SQL server in management studio

$
0
0

I have done all the steps in this

http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/

but still unable to connect to remote sql server, all windows firewalls are disabled, and there is no firewall between them.

I confirmed the server name is correct.

Actually this is the error that I receive when I try to connect:

Cannot connect to Server Instance Name.

A network-related or instance-specific error occured while establishing a connection to SQL Server. The server was not found or was not accessible. ...

When I clicked Connect-> Server Name I click Browse for more... -> then network servers, Unable to locate the network server.


dm_db_index_usage_stats and last_user_update

$
0
0

Im trying to find a way to identify unused indexes for user tables.  When looking at dm_db_index_usage_stats, i see the column "last_user_update" that has very recent date values in it, yet the last_user_seek, last_user_scan and lookup fields are null.  What is the meaning of "last_user_update.  

SELECT u.*, i.name, o.name
FROM [sys].[indexes] i
JOIN [sys].[objects] o
ON (i.OBJECT_ID = o.OBJECT_ID)
LEFT JOIN [sys].[dm_db_index_usage_stats] u
ON (i.OBJECT_ID = u.OBJECT_ID)
AND i.[index_id] = u.[index_id]
AND u.[database_id] = DB_ID() --returning the database ID of the current database
WHERE o.[type] <> 'S' --shouldn't be a system base table
AND i.[type_desc] <> 'HEAP'
AND i.[name] NOT LIKE 'PK_%'
AND u.[user_seeks] + u.[user_scans] + u.[user_lookups] = 0
AND u.[last_system_scan] IS NOT NULL
AND OBJECTPROPERTY(o.[object_id],'IsUserTable') = 1

Question about log contents

$
0
0

Related to another question on the board right now, I always read that the log contains changes made to rows, but does not contain whole (binary) pages, but I don't quite understand what that means for recovery or mirroring.

If on my prod server I run an update statement that changes one column in one row, what exactly is stored in the log - table name or id, column name or id or number, value of course, but also the PK if there is one and if not then some internal ID?

What I'm mostly wondering is how it finds where it needs to be applied in recovery or mirroring situations.  Does it never mention any kind of page ID or location? 

OK, let me mostly answer my own question now, with:

select * from fn_dblog(null,null);

This returns 116 columns of information, including "page id" and "slot id".  So that seems to be the level of abstraction at which it runs, sort of halfway between rerunning the logic and shipping entire pages.

But it seems to me this *could* propagate storage level errors to a mirror, for example.

Thanks,

Josh


Create clustered index with drop existing completed too quickly

$
0
0

I am trying to move all tables  on my SQL Server 2008 R2 database from Primary file group to FG1.

I executed below script on all tables.

Create Unique Clustered Index [MyTable_id_pk] On [dbo].[MyTable] ([MyTable_id] Asc)  With (Drop_Existing = ON, SORT_IN_TEMPDB = ON, Fillfactor = 100, PAD_INDEX = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, DATA_COMPRESSION = NONE) 
On [FG1];
GO

The database is about 500 GB and these tables have millions of rows. Yet the whole  Create clustered index with drop existing code on tables executed under 8 minutes.

How do I verify if it has really moved any data out to FG1?




Ravi Kumar


SQL Agent - Error Authenticating Proxy

$
0
0

I am having an issue when scheduling an SSIS package on a Production environment (via SQL Agent, utilizing a Credential/Proxy). I have worked through the steps below in a Test environment and have not had any problems. Here's what I've done in Production (on a SQL Server 2008 R2 non-clustered environment):

- Copied SSIS package to file system (NTFS permissions are set properly)

- Created a Credential and Proxy (for a Windows user)

- Created SQL Agent job to execute the SSIS package

- Executed the job and receive the following error: 

"Unable to start execution of step 1 (reason: Error authenticating proxy DOMAIN/user, system error: Logon failure: unknown user name or bad password.).  The step failed."

Can someone help me work through this? I have tested the process above with a blank SSIS package, so I know it has nothing to do with access to the source systems. The issue resides specifically on the SQL Server box that is running SSIS and SQL Agent.

I have done some reading and found the following:

- Delegate permissions to SQL Agent account...

- Provide "Log on as a batch job" permissions to AD user

- Install a KB to fix...

Not sure what to puruse at this point. Also, the Job will run just fine using the SQL Agent service account; however, I need to run this user as a different account.

Please advise.


Delete Backup History: Internal Query Processor Error

$
0
0

I was attempting to cleanup backup history, but in doing so I get an error

I ran "exec sp_delete_backuphistory '9/1/2014'" and received the error

Msg 8630, Level 16, State 1, Procedure sp_delete_backuphistory, Line 59

Internal Query Processor Error: The query processor encountered an unexpected error during execution (HRESULT = 0x80040e19).



Lee

Accessing SQL Server over network 100 times slower than local!

$
0
0

I have a C# application developed on a Windows 7 system with a local SQL Server Express database.  The application uses a combination of Entity Framework, LINQ, and T-SQL. Performance in the development environment is great. I recently deployed the application to a new Windows 7 client on a gigabit network connected to a SQL Server 2014 instance running on a Windows Server with tons of disk and RAM. In the network environment, all access to the database is running roughly 100 times slower than the development environment.  I also installed the application on the server itself to test whether the database had an issue, but it was screaming fast on the server - even faster than on the development system. I added the following function to my application to do some testing:

			Stopwatch MyTimer = new Stopwatch();

			MyTimer.Start();

			string connString = GetData.GetConnectionStringByName("MyDB");
			string Query = "INSERT INTO dva.JobHistories (DataSetDSId, EstabName, JobOpenings, JobsFilled) ";
			Query += "VALUES (1, 'Headquarters', 2039, 72)";

			// Connect to the database:
			using (SqlConnection myConnection = new SqlConnection(connString))
			{
				// Open the connection:
				try
				{
					myConnection.Open();
				}
				catch (Exception ex)
				{
					Console.WriteLine(ex.ToString());
				}

				// Execute query and read any results:
				SqlCommand command = new SqlCommand(Query, myConnection);

				// Beginning of timed code:

				for (int i = 0; i < 500; i++)
				{
					command.ExecuteNonQuery();
				}

			// Ending of timed code:
			}

			MyTimer.Stop();
			TimeSpan ts = MyTimer.Elapsed;

			string NiceElapsed = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
				ts.Hours, ts.Minutes, ts.Seconds,
				ts.Milliseconds / 10);

			System.Windows.Forms.MessageBox.Show(NiceElapsed);

When executed on the server, this takes about 0.3 seconds to complete. Executed on the Windows 7 client, over the network, this takes about 100 seconds to complete. This is consistent with other database access done in the application. I have done similar tests in SQL Server Management Studio on the server and on the client with similar results.

I temporarily disabled Trend Micro on both the client and server with no change in performance.

I understand there should be some network latency added, but this is ridiculous. The application is unusable at this point. Before I go to the network admin, I wanted to check if there were some obvious things that would cause this that I can look into and fix.

Unable to Connect to SQL 2000 Instance from Windows Server 2012 environment

$
0
0

We have a windows server (TEST) 2012 environment , where our test SQL Server 2012 instance is hosted.

We have a different (DEV) Server (windows 2000)  where a SQL Server 2000 instance is present.

When I RDP to our Windows Server 2012 box, I cannot connect to the SQL 2000 server instance from SQL Management Studio. (whereas I can connect to the same server from my local machine which has windows 7 and SQL 2012 installed). 

This is the error i see - 

"A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) (.Net SqlClient Data Provider)"

 

When run from SQL Agent Service from TEST (A Job which tries to connect to that SQL 2000 instance to read some data using SSIS) , we get the following error - 

An OLE DB record is available.  Source: "Microsoft OLE DB Provider for SQL Server"  Hresult: 0x80004005  Description: "[DBNETLIB][ConnectionRead (recv()).]General network error. Check your network documentation.".

----------------------------

The same SSIS package runs successfully from my local machine.

Please, could someone advice how to resolve this situation?

 


NT Authority\System vs Localsystem

$
0
0
Hi all, what's the difference between NT Authority\System   vs   Localsystem??

what's the difference using NT Authority\System   vs   Localsystem to start SQL server services??
Viewing all 12963 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>