Quantcast
Channel: SQLServerCentral » SQL Server 2008 » SQL Server 2008 - General » Latest topics
Viewing all 16406 articles
Browse latest View live

Insert Procedure running very slow - Please advice !!!

$
0
0
All,I have a insert procedure, which is running very slow and need you advice.This is SQL2008 versionThis procedure is used to "roll-up" different tables and insert values into result table. Below is the strucure of procedure. Please let me know if any additional information is required.[font="Comic Sans MS"][b][i]Insert into [di_rollup] ([Diag1] ,[Diag1POI] ,[Diag2] ,[Diag2POI] ,[Diag3] ,[Diag3POI]........... till 30)VALUES, Diag1 = CDE_DIAG_1.CodeValue , Diag1POI = CDE_DIAG_1.CodePOIInd , Diag2 = CDE_DIAG_2.CodeValue , Diag2POI = CDE_DIAG_2.CodePOIInd , Diag3 = CDE_DIAG_3.CodeValue , Diag3POI = CDE_DIAG_3.CodePOIInd . . . .. till Diag30POI )FROM CLMLEFT JOIN CDE_DIAG_1 ON On (Primary key columns join here, And CDE_DIAG_1.CodeType = 'DIAG' And CDE_DIAG_1.CodeSequence = '1')LEFT JOIN CDE_DIAG_2 ON On (Primary key columns join here, And CDE_DIAG_2.CodeType = 'DIAG' And CDE_DIAG_2.CodeSequence = '2')LEFT JOIN CDE_DIAG_3 ON On (Primary key columns join here, And CDE_DIAG_3.CodeType = 'DIAG' And CDE_DIAG_2.CodeSequence = '3')....LEFT JOIN CDE_DIAG_30 ON On (Primary key columns join here, And CDE_DIAG_30.CodeType = 'DIAG' And CDE_DIAG_30.CodeSequence = '30')----------and very similer strucure for below four tables. --------- All the below 4 table has primary key deined on 3 columns (compound PK)Insert into [pr_rollup]Insert into [co_rollup]Insert into [oc_rollup]Insert into [cl_rollup]---------Then, below two more inserts having self joinsInsert into TypeRollup (col1,col2........as selected below...)SELECT DISTINCT cpt1.col1, cpt1.col2,... ...... cpt1.col10cpt2.col1, cpt2.col2,... ...... cpt2.col10cpt3.col1, cpt3.col2,... ...... cpt3.col10.....cpt10.col1, cpt10.col2,... ...... cpt10.col10FROM Cache.Claims CLM INNER JOIN PType AS cpt1 ON (Primary key column JOIN AND cpt1.PTypeID = 1) LEFT JOIN PType AS cpt2 ON (Primary key column JOIN AND cpt2.PTypeID = 2) LEFT JOIN PType AS cpt3 ON (Primary key column JOIN AND cpt3.PTypeID = 3) LEFT JOIN PType AS cpt4 ON (Primary key column JOIN AND cpt4.PTypeID = 4) LEFT JOIN PType AS cpt5 ON (Primary key column JOIN AND cpt5.PTypeID = 5) LEFT JOIN PType AS cpt6 ON (Primary key column JOIN AND cpt6.PTypeID = 6) LEFT JOIN PType AS cpt7 ON (Primary key column JOIN AND cpt7.PTypeID = 7) LEFT JOIN PType AS cpt8 ON (Primary key column JOIN AND cpt8.PTypeID = 8) LEFT JOIN PType AS PType AS cpt9 ON (Primary key column JOIN AND cpt9.PTypeID = 9) LEFT JOIN PType AS cpt10 ON (Primary key column JOIN AND cpt10.PTypeID = 10) LEFT JOIN PType AS cpt11 ON (Primary key column JOIN AND cpt11.ProviderTypeID = 11) WHERE CLM.PKey = @PartKey (Primary Key column)[/i][/b][/font]Attached is the query plan for same. Kindly suggest what is causing to run this procedure slow and what can be modified to improve the performance of same.Thank youPrasad

Query takes 1.5 minutes from SQL but more than 1 hour from application

$
0
0
We have one query which used by users to pull the report everyday in the morning. Which, i generally run through SQL and it takes only 1 to 2 minutes but it takes forever for users to pull the report from application.Statistics are updated and indexes seems looks good too. Is there anything else i can do run the query faster?

dynamic sql performance and implementation recs?

$
0
0
I'm working on a new service that will need to provide reporting data for regions. Each region will have its own db table and each db table will have some columns with the same name like ReportDate. The different tables will have a lot of different/unique columns which is why I created a separate table for each region. There will be about 10 region tables.I'm considering using dynamic sql for my sproc so I can write a simple query and then run it generically against each table. This would be much quicker and easier to write and maintain then writing 10 separate queries that perform the same SQL against all tables.Is SS pretty well optimized to handle this type of implementation? Do you see any potential performance issues? Are there any specific steps I should take to optimize performance for this implmentation? Does anyone here think dynamic sql is "evil" for one reason or another? I'm referring specifically to dynamic sql completely done within SS as opposed to an external app passing in dynamic sql statements.

Random Unique Number Always

$
0
0
Hello, I have a stored procedure that will be executing on a recurring basis at different intervals. There is a field that I need to populate with a random unique number but once I use one, I can never use it again. As this procedure will be called all the time and not just once, how do I ensure that I never use the same random number?I was generating it with this code: (SELECT FLOOR(RAND()*(100000-1)+1))But, it occurred to me that there is a small possibility that it could somehow pick the same number as a previous call to the stored procedure? Do I need to actually store the ID somewhere and tell it not to use one that already exists?Thanks!

The transient database snapshot for database 'DB1' (database ID 5) has been marked suspect due to an IO operation failure.

$
0
0
I have looked all over google regarding 'snapshots' in SQL 2008 and I have been reading up on their function and how they are created and removed as well as where you can review them from SSMS...I have NOT found anything of relevance regarding the actual error message. I did find a couple blog posts regarding the error message and DiskKeepper 2010 but that doesn't apply to my situation.We have an SAP instance that has several different kind of landscapes, on the particular server in question there is a lot of activity during the period of a DBCC check being performed.A lot of Disc I/O is generated...sometimes we get the error message in the subject. Additional executions of the DBCC even when nothing is running will fail.once the server is rebooted and the DBCC is started again then it works just fine.I am curious if someone has a different view point on the error listed above.The error is occurring on a SQL 2008 x64 enterprise edition hosted on windows 2008 enterprise. The servers are all virtual servers on an EMC sanAny discussion is appreciated.Thanks,Lee

ssis package to load data

$
0
0
i created ssis package that load data from source to destination.i have 4 columns in source and destination.now they are adding new column every month.i want my ssis package to add this functionality automatically,without changing my package automatically.how to do it in ssis

List out all Log On As account details in Services.msc

$
0
0
Hi All,If I need to extract all the services.msc services "Log On As" account details and the "Startup Type", how will I find the details?Is there any Powershell cmdlets/WMI SQL Scripts available to get the details?Please suggest.

Lock level

$
0
0
Dear all,I have some stored procedures that I was calling one by one and passing a variable with the market code. All using the same connection.Like 1 - Open connection. 2- Execute sp1. 3 - Execute sp2 ....(those are 7 stored procedures)Now a new team started to trigger this but instead of triggering 1 by 1 till the seven finish, they are doing the opposite. They are executing 5 times the same stored procedure in parallel , each one with a sifferent parameter.This is taking a lot of time. it seems we have several locks (not deadlocks).I know that I can decrease the isolation level inside stored procedures so that they don't cause locking.What is the lowest level ?Also, when the stored proc ends, the isolation level gets to its normal state?thank you

New 2008 R2 Installation Errors

$
0
0
I have a freshly installed SQL Server and I keep getting the same error on some of the actions I attempt. When I right click a database and go to Tasks > Import Data and when I right click a table and go to delete, I get the following error:"Cannot show requested dialog. Additional information: Could not load file or assembly 'Microsoft.SqlServer.Sqm, Version = 10.0.0.0, Culture = neutral, PublicKeyToken = 89845cd8080cc91' or one of it's dependencies. The system cannot find the file specified. (SqlMgmt)"I tried to go through this with my clients DBA but he told me to copy the file from the Program Files into two directories and then register them (the above .dll) but they won't register. He got frustrated and gave up on me. Any ideas?

schema, login account permissions

$
0
0
Want to gather a report to find what are all the schema a specific login account have along with that what are all the specific object level permission does it have.If you have any specific easy script do share that with me.

Temporary tables

$
0
0
Dear all,If I have a stored procedure creating and filling a temp table like #tempo1. This is using a connection we can call it Conn1Then I am executing exactly the same procedure but using a dif connection. Let us call conn2Question:Because both create and fill a temp table called #tempo1 and because they run at the same time. Can one fill the temp table of the other?thank you

witness server issue

$
0
0
Hi All,I have an issue when I set up witness server to monitor principal and mirror server . Mirroring session is successfully created between principal and mirror. Only witness server is the issueThe error that I get is as below :“ The Alter database command could not be sent to the remote server instance ‘TCP://xxxxxxx:5022’. The database mirroring configuration was not changed . Verify that the server is connected and try again”The situation is : I can connect to witness server from principal server via SQL Management Studio BUT I can’t ping witness server from there Is there anything that I can do to fix this?Thank you Cheers…

Quert Required

$
0
0
Dear AllI want Query for following scenario. In My table we are storing each student three level of marks. I want to find out final marks. Create table #ResultData (Registerno varchar(12), LevelOneMark int,LeveltwoMark int,LevelthreeMark int)insert into #ResultData values ( 'R1',80,20,86)insert into #ResultData values ( 'R2',10,20,86)insert into #ResultData values ( 'R3',10,20,30)In this Above table I want to find final mark of each student. Based on least difference I want to find final markScrio 1: (a-b,b-c,c-a)80-20=6020-86=6686-80=6In this above scenario least difference is 6 . So I want to final result (86+80)/2=83Scrio 2: (a-b,b-c,c-a)10-20=1020-86=6686-10=76In this above scenario least difference is 10. So I want to final result (10+20)/2=15Scrio 3: (a-b,b-c,c-a)10-20=1020-30=1030-10=20In this above scenario least difference is 10.But difference 10 is two category. In this condition I want to go student favour. So I want to final result (20+30)/2=25.I want Result for following resultRegisterno, LevelOneMark, LeveltwoMark, LevelthreeMark , FinalMarkR1, 80, 20, 86,[color="#FF0000"]83[/color]R2, 10, 20, 86,[color="#FF0000"]15[/color]R3, 10, 20, 30,[color="#FF0000"]25[/color]Please help me

Database audit specifications

$
0
0
Hi,I have an audit spec which covers inserts, updates and deletes on certain tables i.e.ADD (DELETE ON OBJECT::[dbo].[T1] BY [dbo]),ADD (INSERT ON OBJECT::[dbo].[T1] BY [dbo]),ADD (UPDATE ON OBJECT::[dbo].[T1] BY [dbo]),Can anybody explain why the statement below gets audited with an action_id of 'UP' which is update please?thanks.select TABLE_CATALOG = s_cv.TABLE_CATALOG, TABLE_SCHEMA = s_cv.TABLE_SCHEMA, TABLE_NAME = s_cv.TABLE_NAME, COLUMN_NAME = s_cv.COLUMN_NAME, COLUMN_GUID = s_cv.COLUMN_GUID, COLUMN_PROPID = s_cv.COLUMN_PROPID, ORDINAL_POSITION = s_cv.ORDINAL_POSITION, COLUMN_HASDEFAULT = s_cv.COLUMN_HASDEFAULT, COLUMN_DEFAULT = s_cv.COLUMN_DEFAULT, COLUMN_FLAGS = s_cv.COLUMN_FLAGS, IS_NULLABLE = s_cv.IS_NULLABLE, DATA_TYPE = s_cv.DATA_TYPE, -- Used by Katmai+ clients TYPE_GUID = s_cv.TYPE_GUID, CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH = s_cv.CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION = s_cv.NUMERIC_PRECISION, NUMERIC_SCALE = s_cv.NUMERIC_SCALE, DATETIME_PRECISION = s_cv.DATETIME_PRECISION, CHARACTER_SET_CATALOG = s_cv.CHARACTER_SET_CATALOG, CHARACTER_SET_SCHEMA = s_cv.CHARACTER_SET_SCHEMA, CHARACTER_SET_NAME = s_cv.CHARACTER_SET_NAME, COLLATION_CATALOG = s_cv.COLLATION_CATALOG, COLLATION_SCHEMA = s_cv.COLLATION_SCHEMA, COLLATION_NAME = s_cv.COLLATION_NAME, DOMAIN_CATALOG = s_cv.DOMAIN_CATALOG, DOMAIN_SCHEMA = s_cv.DOMAIN_SCHEMA, DOMAIN_NAME = s_cv.DOMAIN_NAME, DESCRIPTION = s_cv.DESCRIPTION, COLUMN_LCID = s_cv.COLUMN_LCID, COLUMN_COMPFLAGS = s_cv.COLUMN_COMPFLAGS, COLUMN_SORTID = s_cv.COLUMN_SORTID, COLUMN_TDSCOLLATION = s_cv.COLUMN_TDSCOLLATION, IS_COMPUTED = s_cv.IS_COMPUTED, SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_cv.SS_XML_SCHEMACOLLECTION_CATALOGNAME, SS_XML_SCHEMACOLLECTION_SCHEMANAME = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME, SS_XML_SCHEMACOLLECTIONNAME = s_cv.SS_XML_SCHEMACOLLECTIONNAME, SS_UDT_CATALOGNAME = s_cv.SS_UDT_CATALOGNAME, SS_UDT_SCHEMANAME = s_cv.SS_UDT_SCHEMANAME, SS_UDT_NAME = s_cv.SS_UDT_NAME, SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME, SS_IS_SPARSE = s_cv.SS_IS_SPARSE, SS_IS_COLUMN_SET = s_cv.SS_IS_COLUMN_SET from sys.spt_columns_view s_cv where ( (@table_schema is null and s_cv.TABLE_NAME = @table_name) or s_cv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name)) ) and (@column_name = s_cv.COLUMN_NAME or @column_name is null) order by 1, 2, 3, 7

SQL Server 2008 Task generate script

$
0
0
I am using Task > Generate script to create a sql insert script.Is there any way I can change table name while generating insert script ?I was looking at Advanced > Options ...but could not find anything.Is there anything I'm missing ?[u]Example:[/u]source table say TESTI want generate script to make a table TEST_TEMP

Indexed, Foreign Keys and Primary Keys

$
0
0
Bascially we have a db which is on muliple instances, used by differant companies.Somewhere along the way, indexes have gotten differant names, PK have differant names etc.We want to as a starting poistion standardise them across the dbs.Can we simply script a create of all objects on one db.Drop them all and create on the other db, from the first one?Is there a better solution and obvious problems to this?So for FKshttp://blog.sqlauthority.com/2008/04/18/sql-server-generate-foreign-key-scripts-for-database/Thanks

Blocked Process Alert issues

$
0
0
This is really beginning to annoy me.I have Blocked Process Alerts on every single server in our environment. The alerts are set to email us when the blocked processes get above 2. So what happens? Our DEV server (not Production, not any of the others) is constantly sending emails out about the blocked processes. I finally got annoyed and set up a job to try and catch the blocked processes (runs every 3 minutes). The problem is, the job isn't catching the events that trigger the alerts. In fact, it's catching other blocking events that don't trigger the alerts. I'm about at my wits end.Does anyone have any suggestions on code that can assist me with catching whatever is causing the alerts?The code I'm using I got from Ian Stirk's website / blog. It's attached for reference if you want to see it.

sqlcmd adding/modifying date to filename

$
0
0
We're using the SQLCMD command to extract content from a database and place into an output file. Set that up and it works fine. Then a date was attached to the output file name - that works fine. Last effort to subtract one day from the date and we're stuck.This is what we've tried so far:sqlcmd -S server -d database -E -W -w 900 -s "," -i F:\query-location.sql -o F:\output-file.csv -- this works.Then added the date:sqlcmd -S server -d database -E -W -w 900 -s "," -i F:\query-location.sql -o "F:\output-file$(ESCAPE_NONE(DATE)).csv" -- this works as wellNow the problem area:sqlcmd -S server -d database -E -W -w 900 -s "," -i F:\query-location.sql -o F:\\output-file$(ESCAPE_NONE(select cast (GETDATE() - 1 as DATE)).csv -- this kicks out a syntax error. Is there syntax to do this without using xp_cmdshell or powershell? Googling this we found an article suggesting xp_cmdshell. While that looks like it will work - don't know if that's the route to go. Any comments / syntax recommendations / URLs would be appreciated.Thank you.

SQL Agent CmdExec fails with no message

$
0
0
I'm having a problem running a job that calls CmdExec. The step output is just this:[quote]Date 9/15/2016 4:31:52 PMLog Job History (TheJobName)Step ID 1Server TheServerJob Name TheJobNameStep Name TheStepNameDuration 00:00:00Sql Severity 0Sql Message ID 0Operator Emailed Operator Net sent Operator Paged Retries Attempted 0MessageExecuted as user: TheSqlAgentUser. The step failed.[/quote]I know that the path is correct because if I change it, then it tells me that it can't find the file. The cmdexec looks like this:\\share\path\TheProgram.exeThe program is a console application developed in .NET. The console application runs successfully if started outside SQL Agent. This program is replacing an existing program (which was also a console application) that had been running via the same job successfully. While the program displays data to the console (data which is also logged elsewhere), it does not require any input from the console. I don't care if the console is visible. It's a long-running application, so it should leave the job in a running state, not in an immediate failure state.To add complication to this scenario, the server on which this is running was recently replaced. All software was reinstalled and the database was restored. So it's possible that any special configuration that was done to allow SQL Agent to run this job was lost. The knowledge of that configuration, if any, was lost years ago when the initial developer left.The application should be logging, but it appears the error, whatever it is, occurs before the app starts. The very first thing this application does in main is to log that it's been started.If only I had an error message to work with...Ideas?

Optimize update with an index

$
0
0
Hi Guys ,I am wondering how to optimize this below update statement as it probably cause table scan :Update Table1Set a=@a , b = @b , c =@cWhere id =@id and name=@name , file =@file , lastupdated = @lastupdated Should I create index on column in where criteria -> non clustered index on id, name and lastupdatedAny feedback are much appreciated Thank you
Viewing all 16406 articles
Browse latest View live