Tuesday, April 2, 2013

[SQL Server] Audit Trail

[SQL Server] Audit Trail


Audit Trail

Posted: 02 Apr 2013 07:16 AM PDT

Hi,I have a question about how to approach a audit trail requirement for my application. I need to perform audit trails on certain situations so I would like to automatically log with the data records. The data I will like to log are the program name, user, host of the session performing the inserts, updates, deletions of records. I am taking this approach because based on the system requirements I know for example that some inserts should only be done via programX so if I see an insert from a different program I should flag that record on my audit trail report. I see were I can use the system DM to get the information so could modified my store procedures to get the information and update the necessary fields in the records. Or should I create triggers to automatically handle this. thanks

Help with replication scenario

Posted: 02 Apr 2013 07:45 AM PDT

I have a scenario at work where I need to replicate (in the general sense, not necessarily in the "sql server replication" sense) a database in approximate realtime between two instances on separate servers. The source server is running sqlserver 2000 standard and is a 24x7 database running a vendor-supplied dispatch program. Altering the structure of this DB is a non-starter.The destination server runs sqlserver 2008r2 and does web services.I tried setting up a transactional replication publication on the source, but it failed because several of the tables have > 255 columns. I got errors saying the articles couldn't have this many columns, and the snapshot couldn't be created.So I looked at doing mirroring, but I don't think I can do database mirroring with server 2000, correct?I also looked into log shipping, but apparently you need sqlserver 2000 enterprise to do log shipping (later releases do it with any version of the db).Does anyone have advice or corrections for me? Can I do mirroring? Can I make log shipping happen with 2000 standard edition? Is there an easy fix for replication of big tables?Also, is the 255 columns limitation specific to sqlserver 2000, or do all releases have that limit?

Had a job failure but it doesn't appear in the job history

Posted: 08 Mar 2013 01:36 AM PST

Hello,I am documenting job failures in the last two months and I cannot find the one that we had in that period. I looked in the job history and also in the event logs. Can a job fail without recording it? Is there something I have to set to make it write to the job history (I've never known that to be the case)? Thank you in advance.

Available disk space policy

Posted: 01 Mar 2010 06:35 AM PST

Hi everyone. I designated a SQL Server 2008 instance to act as a central management server. It is running a really nice tool called Enterprise Policy Management Framework that reports policy failures on a dashboard.I would like to design a policy that looks at the disk space that I am using to store my SQL Server backups and reports when the space is low.For example, a policy that evaluates <used drive space of backup volume> <= <80% of total drive space of backup volume> so that I have a warning when my backups might soon fail.I found a field called @AvailableSpace in the policy wizard but I don't see one for total space.Am I approaching this right?Thanks much,Howard

Stupid Question: Return Object Explorer to It's original position

Posted: 26 Nov 2010 07:57 AM PST

Stupid question but I accidentally moved object explorer from it's original default position on SSMS. By default, object explorer is to the left, and query window is to the right. Now object explorer seems to have been "undocked" and query window occupies the screen from left to right, such that if I open a new query it opens "behind" object explorer. How do I restore the original "default" view in SSMS?

[MS SQL Server] Length limitation on domain accounts?

[MS SQL Server] Length limitation on domain accounts?


Length limitation on domain accounts?

Posted: 02 Apr 2013 04:11 AM PDT

I'm attempting to create a login from a Windows account like so:[code="sql"]USE [master]GOCREATE LOGIN [DOMAIN\MyLongerThan20CharacterServiceAccount] FROM WINDOWS WITH DEFAULT_DATABASE=[master];GO[/code]But this fails with the error:[i][b]Msg 15401, Level 16, State 1, Line 1Windows NT user or group 'DOMAIN\MyLongerThan20CharacterServiceAccountnot found. Check the name again.[/b][/i]This account however does exist. If I attempt to shorten it to 20 characters (pre-Windows 2000 format) it works![code="sql"]USE [master]GOCREATE LOGIN [DOMAIN\MyLongerThan20Charac] FROM WINDOWS WITH DEFAULT_DATABASE=[master];GO[/code]Has anyone ran across this 20 character limitation before? I'm assuming there is a simple fix or configuration setting to correct this behavior but I'm hoping someone can chime in on what that is.

CPU Consuming nearly 100%

Posted: 02 Apr 2013 04:08 AM PDT

I have a SQL Server 2008 R2 VM Server with SAN Disk Storage.The SQL Server process is using nearly 100% with only one job running.I had the same problem with this server last week. I got all of the user of the box and it was still consuming 100%.Then I restarted the Service and with no active connections it quickly jumped up to 100%.The Network Guy said that it was not as as result of the SAN this time but he was looking into an issue with the NIC.Shortly after the CPU % dropped to normal levels.He claimed that he did not do anything and claimed that it was the loads. Never mind that it was 100% with no users connected.Any ideas?

Cant Restore Differential Backup

Posted: 02 Apr 2013 01:52 AM PDT

I restored a Full Backup from 12:30 AM this morning and I specified WITH NORECOVERY.Then I attempted to restore a differential Backup that I made at 10:30 AM and I specified WITH RECOVERY.However I get the following error as if I had specified recovery on the full backup:[quote]Msg 3136, Level 16, State 1, Line 1This differential backup cannot be restored because the database has not been restored to the correct earlier state.Msg 3013, Level 16, State 1, Line 1RESTORE DATABASE is terminating abnormally.[/quote]Any ideas would be greatly appreciated?

Best practice to create a new database for Datamart

Posted: 02 Apr 2013 01:02 AM PDT

Hi,Is there any guidelines for creating a database for OLAP system.

Primary file group out of space

Posted: 02 Apr 2013 12:20 AM PDT

If the primary file group runs out of space and its file growth is restricted, and if the table exists on primary FG, can I still insert into this table by adding a new file on a different disk?

Scripts To Monitor SQL SERVER

Posted: 01 Apr 2013 04:23 PM PDT

Hi Everybody , it's been two or three weeks I'm trying to find scripts to monitor different SQL SERVER indicators, but I can't find. Could someone help me Plz?- Weekly CPU (to create a graph for 7 days )-Weekly Buffer Hit Ratio

Attempted to perform an unauthorized operation

Posted: 18 Aug 2010 11:22 AM PDT

Hi,I'm installing SQL Server 2008 x64 developer edition on Windows Server 2008 x64. I installed the SQL Server 2008 many times with no issues.But this time I have changed Shared feature directories as below: Shared feature directory as D:\Program Files Shared feature directory (x86) as D:\Program Files(x86)and now ending up with the below error:TITLE: Microsoft SQL Server 2008 Setup------------------------------The following error has occurred:Attempted to perform an unauthorized operation.Click 'Retry' to retry the failed action, or click 'Cancel' to cancel this action and continue setup.Is changing the above directories will be the reason for the SQL Server 2008 installation failure?Is this allowed to change the above directories Shared feature directory & Shared feature directory (x86) from default directories C:\Program Files & C:\Program Files(x86)?I even tried the Repair option and then again getting the same errorThanks

[Articles] Salaries in 2013

[Articles] Salaries in 2013


Salaries in 2013

Posted: 01 Apr 2013 11:00 PM PDT

The release of an extensive salary report for Information Technology shows some good trends in it for 2013.

[SQL 2012] Upgrade the Sql server 2005 Instance to Sql Server 2012.

[SQL 2012] Upgrade the Sql server 2005 Instance to Sql Server 2012.


Upgrade the Sql server 2005 Instance to Sql Server 2012.

Posted: 01 Apr 2013 11:46 PM PDT

Hi,can we run the SQL Server 2012 at Production Instance or is it still in the testing phase.Can we upgrade the SQL Server 2005 Instance Directly to SQL Server 2012 Instance.What are the points we need to take care at the time of upgradation.Is anything in the Code(SP/UDF/View Script), we need to change which is not supported in SQL Server 2012.Can we deploye the same SSIS 2005 Packages to SSIS 2012 Packges. Is anything changed in the SSIS 2012 from SSIS 2005.Thanks & RegardsNitin Varshney.

SQL Server Agent 2012 - Slow on startup and closure

Posted: 01 Apr 2013 09:29 PM PDT

Dear SQL users, Since couple of weeks we've been working with [b]SQL Server 2012[/b] (Microsoft SQL Server 2012 - 11.0.2100.60 (X64) Standard Edition (64-bit) (Build 7601: Service Pack 1). We still have our old production centre which works on SQL Server 2005. The problem lies within the SQL Server Agent, all Agent settings are similar to our good working 2005 environment. A simple job with single t-sql step 'select @@version' takes over [b]40 seconds [/b]in 2012 and < 1 second in 2005 environment. Running the query in 2012 query window it has the same (expected) performance of < 1 sec.What is it that makes the 2012 Agent so slow? Interesting is that the job step takes 6 seconds and the total job takes 40 seconds.[b]Any ideas??[/b]Thanks in advance, Gr. Erik

Hotfix Fails with "Could not write value SupportFiles to key..."

Posted: 01 Apr 2013 07:16 AM PDT

I tried to apply a hotfix on my PC to fix a bug ([url]http://support.microsoft.com/?kbid=2793634[/url]). It failed with errors such as "Could not write value SupportFiles to key \Products\F3170BC80EFCD544CB2B35485668E0A1\Features. Verify that you have sufficient access to that key, or contact your support personnel". I am a local admin on my PC. Any ideas? My computer is running Windows 7 Professional SP1. I currently have SQL Server 2012 SP1 installed (11.0.3000).Thanks!

[T-SQL] Selection using date held as a string

[T-SQL] Selection using date held as a string


Selection using date held as a string

Posted: 01 Apr 2013 09:11 PM PDT

In our database we have a parameters table that holds a parameter type (e.g. D for date, N for number, I for integer etc) and then a varchar column which holds the parameter value.In the case of dates, the data is held in the format 'yyyy-mm-dd hh:mm:ssZ' which will convert quite hapily into a Datetime2 datatype for displayExample Data values (key_value):2013-10-29 22:59:00Z2013-04-25 23:59:00Z2013-03-06 22:59:00Z2013-03-06 22:59:00Z2013-03-06 22:59:00Z2013-03-29 22:59:00Z2013-03-06 22:59:00Z2013-04-27 23:59:00Z2013-03-06 22:59:00Z2013-04-03 23:59:00Z[code="sql"]SELECT TOP 10 key_value ,convert(datetime2,BPK.key_value) as DT2 ,convert(datetime,CONVERT(DATETIME2, PV.key_value)) AS DT FROM parameter_value PV WHERE PV.datatype = 'D'[/code]Displaying the data is not a problem, but when I try to use the data in selection criteria, it fails with a 'Conversion failed when converting date and/or time from character string.'e.g.[code="sql"]SELECT TOP 10 key_value ,convert(datetime2,BPK.key_value) as DT2 ,convert(datetime,CONVERT(DATETIME2, PV.key_value)) AS DT FROM parameter_value PV WHERE PV.datatype = 'D'and convert(datetime,CONVERT(DATETIME2, PV.key_value)) BETWEEN GETDATE() and DATEADD(d, 10, GETDATE())[/code]It doesn't seem to matter how I convert the data - to Dattime, Datetime2, Varchar etc - I always get the conversion error when the data is used in a WHERE clause.Any insights?

Help with Query

Posted: 01 Apr 2013 08:30 AM PDT

Hi I have a query which returns the followingKey segment ValueA001 001 3A001 002 4A001 003 4A002 001 2A002 002 2A002 003 1A003 001 4A003 002 4A003 003 4I would like to change the query so it only returns the first row for each Key which contains the max value for the key. The output I want with look like the followingKey segment ValueA001 002 4A002 001 2A003 001 4Thanks in advance.

Add Auto Incrementing column to my SELECT statement

Posted: 01 Apr 2013 02:34 AM PDT

Along with the data that I am pulling back from query, I also need to provide an ImportID column with the following requirements:YYMMDDGP0001, YYMMDDGP0002, YYMMDDGP0003, and so on. The 0001, 0002, and 0003 part could get big into the hundreds of thousands.I have the YYMMDDGP part down with the following expression:SELECT CONVERT(VARCHAR(6), GETDATE(), 12) + 'GP' AS [ImportID]Now I need to get the Auto Incrementing number part of this. I have been researching this trying SELECT INTO a temp table using the Identity Function and declaring different variables all with no luck. If someone could point me into the right direction on this or if you have a snippet of TSQL that will work for me, I would greatly appreciate it.Thanks Again!

Get summary of column values from a result set

Posted: 01 Apr 2013 06:08 PM PDT

good morning everyone,I have a procedure taking some input parameters that are used for a select statement. After returning the select statement I need the distinct values of 2 columns as comma seperated list.The only solution seems to be that I do the select 3 times: once for the result and once for each column I want the distinct values for. This summary is needed by the reporting tool calling the procedure for showing it to the user.Is there a better solution? Here's the (very simplified) example:[code="sql"]-- This is my base tabledeclare @CustomerOffices table ( OfficeId int, CustomerName varchar(100), PostalCode char(4) );insert into @CustomerOffices ( OfficeId, CustomerName, PostalCode ) values ( 1, 'Cust1', '6020' ) ,( 3, 'Cust5', '8010' ) ,( 4, 'Cust5', '8010' ) ,( 5, 'Cust3', '6020' ) ,( 6, 'Cust3', '5020' ) ,( 7, 'Cust2', '6020' ) ,( 8, 'Cust2', '1030' ) -- this is part of an sql procedure, taking the OfficeId as inputdeclare @FromOfficeId int, @ToOfficeId int;-- We want to have OfficeId 4 to 7set @FromOfficeId = 4;set @ToOfficeId = 7;-- This is our resultselect OfficeId, CustomerName, PostalCodefrom @CustomerOfficeswhere OfficeId between @FromOfficeId and @ToOfficeId;[/code]Now I want to have all distinct CustomerNames and all distinct PostalCodes of the result above.[code="sql"]declare @SummaryCustomerNumbers varchar(max) = '', @SummaryPostalCodes varchar(max) = '';select @SummaryCustomerNumbers += s.CustomerName + ','from ( select distinct CustomerName from @CustomerOffices where OfficeId between @FromOfficeId and @ToOfficeId ) as sorder by s.CustomerName;select @SummaryPostalCodes += s.PostalCode + ','from ( select distinct PostalCode from @CustomerOffices where OfficeId between @FromOfficeId and @ToOfficeId ) as sorder by s.PostalCode-- Remove last kommaset @SummaryCustomerNumbers = left( @SummaryCustomerNumbers, len( @SummaryCustomerNumbers ) - 1 )set @SummaryPostalCodes = left( @SummaryPostalCodes, len( @SummaryPostalCodes ) - 1 )select 'Summary' as Summary, @SummaryCustomerNumbers as CustomerNumbers, @SummaryPostalCodes as PostalCodes;[/code]This is a quite complicated way and, as I said, I have to do the same select 3 times. As the original select is done on a large table the procedure needs quite a lot time to do this.I already tried to use the compute clause but it only works for aggregate functions.For getting the whole thing faster I could save the original result in a temp table and get the distinct values from the temp table. But that's not very elegant, isn't it?Thank's for any help.

Stored Procedure using huge IO?

Posted: 01 Apr 2013 05:44 PM PDT

Hi,one of the SQL SP written like this as below. it is getting blocking every time due to waiting IO pending for compeletion... please suggest me how to resolve blocking and optimize this sp. is there any alternative way re-write this sp?each table having total records 2334567[code="sql"]Create procedure [dbo].[DeleteforRetention] @LastChangeDate DateTimeasbegindelete from dbo.OperatingLimitHighValues_tracking where OperatingLimitHighValue_PK_ID in (select a.OperatingLimitHighValue_PK_ID from OperatingLimitHighValues a where a.EffectiveTime<@LastChangeDate and EffectiveTime not in (select MAX(EffectiveTime) from OperatingLimitHighValues b where b.OperatingLimit_PK_ID=a.OperatingLimit_PK_ID)) delete from dbo.BoundaryHighValues_tracking where BoundaryHighValue_PK_ID in ( select a.BoundaryHighValue_PK_ID from BoundaryHighValues a where a.EffectiveTime < @LastChangeDate and EffectiveTime not in (select max(EffectiveTime) from BoundaryHighValues b where b.Boundary_PK_ID = a.Boundary_PK_ID)) delete from BoundaryHighValues where BoundaryHighValue_PK_ID in(select a.BoundaryHighValue_PK_ID from BoundaryHighValues a where a.EffectiveTime < @LastChangeDate and EffectiveTime not in (select max(EffectiveTime) from BoundaryHighValues b where b.Boundary_PK_ID = a.Boundary_PK_ID)) endGO[/code]Thanksananda

Transaction Isolation Level

Posted: 01 Apr 2013 09:12 AM PDT

Hello EveryoneI have a medium sized SSIS Package, with multiple steps, that call a single sproc each. I am working on a query that I am having to change the database Transaction Isolation Level approx 3/4 of the way thru the package steps.I alter the Transaction Isolation LevelSET TRANSACTION ISOLATION LEVEL SERIALIZABLE;Begin Tran BlahBlahSome Update Query is hereUpdate Query CompletesCommit Tran BlahBlahMy question is: does the Isolation Level get set back to the database default after the commit, or after the package is complete?There are other processes that use some of the tables that the queries in the spocs have already used after I have changed the Isolation Level. I am thinking that I should set it back to the database default, so that the other processes can use the table that I just updated in the Update query that is between the Begin and Commit trans.Thank you in advance for all your assistance, comments and suggestionsAndrew SQLDBA

TRIGGERS...

Posted: 01 Apr 2013 07:23 AM PDT

Hey guys, Our team ran into a problem over the weekend and Im confused over it...We are in the process of migrating to a new system! The new system does not have anything to track the history of an application. When an application gets entered and goes through each step of the workflow, it gets updated, it just updates the single row in the table for that app...Well we need a history of the app as it relates to when it goes through each step in the workflow so my boss and I came up with the idea to create triggers on that table (INSERT, UPDATE, and DELETE) so when an application gets inserted, it will write that to another table, when it goes through the steps of workflow, each step gets captured with the UPDATE trigger and written to that other table, and when the application goes through all the steps, it gets deleted from that main table and that record goes into the other table with the DELETE trigger...Now my boss has some horror stories from the past with triggers because he had used them as a FOR instead of AFTER...So we made sure all the triggers were set up as AFTER triggers meaning that after the insert, update, or delete happens THEN the trigger fires off and does what it needs to do! Well when we went live to the new system, they were noticing after they pushed an application through the workflow, it was not getting deleted! I had an error on my DELETE trigger (rookie mistake: I was calling a table from the dev environment) so it was not allowing the delete to happen! Now to me, an AFTER trigger is a trigger that will fire AFTER the statement happens...So when you go to delete something, the delete would happen then the trigger would fire off, but apparently that is not the case! It was not allowing the delete to happen b/c of my trigger failing! In research, even the way MSDN words it, it sounds as if our assumption was correct:http://msdn.microsoft.com/en-us/library/ms189799%28v=sql.100%29.aspxFOR | AFTER AFTER specifies that the DML trigger is fired only when all operations specified in the triggering SQL statement have executed successfully. All referential cascade actions and constraint checks also must succeed before this trigger fires.AFTER is the default when FOR is the only keyword specified. AFTER triggers cannot be defined on views. You can see that our assumptions of the trigger not causing any problems were well founded. At best, this documentationis misleading. In my mind "All operations" includes the committing of the delete transaction.Can someone explain AFTER trigger to me as to why it would not allow the delete to happen b/c of trigger failure even though the trigger was an AFTER trigger?

[SQL Server 2008 issues] update stats

[SQL Server 2008 issues] update stats


update stats

Posted: 01 Apr 2013 06:37 PM PDT

How update stats works in sql ?

oracle 9i to Sql server 2008 R2 migration

Posted: 01 Apr 2013 07:09 PM PDT

Hi,We are having oracle 9i as database and migrating to sql server 2008.Our oracle 9i database connects to another oracle databases and these databases are having different oracle version(9.2.0.8.0, 9.2.0.7.0,10.2.0.5.0,11.2.0.2.0,9.2.0.6.0,10.2.0.4.0,8.1.7.4.0 )I do have two queries :1) how to connect from Sql server 2008 R2 to different Oracle databases2) How will other oracle databases connect to Sql server 2008 R2 database

Data Compression in SQL Server: Shubham Saxena

Posted: 01 Apr 2013 06:31 PM PDT

Dear Friends,Please help!!I need to build up a function or stored procedure to compress/decompress a large object.like image or blob please provide me script to compress and decompress image in SQL.Thanks !!:-)

How to write custom query which shows last two records added only.

Posted: 01 Apr 2013 06:04 PM PDT

For Insurance where logic is something like after renewing a policy that renewed policy is current policy and previous policy will not be current anymore. Now want to show customer this last two records i.e. renewed policy as well as original policy which was renewed. And while renewing current policy of original policy will become previous policy for renewed policy. query i am using to show current policy only or renewed policy is something like:select * from table_name where is_current='Y'Modified to select * from table_name where person_id=somevalue OR Prev_PolNO=Curr_PolNobut still it doesn't give correct result.So can same be achieved.......

Suspended process in msdb database

Posted: 05 Dec 2012 04:00 PM PST

Hello gentsI have right now a suspended spid 53 at msdb which is in suspended status for over 2 hours. Seen from sp_who2, the 'cmd' it is doing is 'delete' and the login behind this process is "NT AUTHORITY\SYSTEM" from program name "Microsoft Windows Operating System".In addition, lastwaittype is BROKER_RECEIVE_WAITFOR and I ran dbcc opentran in msdb and it returns:Oldest active transaction:spid: 53UID: -1Name: receiving msgStart time: <the time i ran "dbcc opentran">Any ideas where else I should look at?Thanks in advance!

Cannot convert between Unicode & Non Unicode Strings Error

Posted: 01 Apr 2013 03:41 PM PDT

Hi,I have a SSIS package that imports an ADO.Net source file & inserts into an OLEDB Destination.There are about 25 fields but one field errors when tryingto run this task.The field represents an Account number which is a varchar (15) in both the source & destination tables.I tried fixing this by adding a Data Conversion node to change the Account number from DT_WSTR to DT_STR as I found an answer on a forum about this problem but no luck, same error.Can anyone advise how I can fix this & why does it happen?Thanks

Can I move the older ERRORLOG files?

Posted: 01 Apr 2013 01:22 PM PDT

Hi all,Long story short, we had a process that was filling up our log file at an impressive rate (impressive in a bad way). We got everything under control and that particular error log file is no longer the "current" one. However, it's taking up quite a bit of space on one of our drives. So, I'd like to move it to another drive to free up some extra room.I know I can cycle the log files until the log file in question just gets auto-deleted, but I'd like to keep it around a bit longer so we can look through it and troubleshoot.Can I manually move the files (such as ERRORLOG.2, ERRORLOG.3, etc)? Is there a super secret sp for doing this? How does SSMS like having those files manually moved without its consent?Thanks!

sql query to be accessed online

Posted: 01 Apr 2013 07:41 AM PDT

HiI just want to figure how to have a sql query that I generated in excel form and I want to put it online and I want it to update it self. is that possible?Thank you

A severe error occurred on the current command. The results, if any, should be discarded.

Posted: 01 Apr 2013 12:17 AM PDT

Hi While running the query , I am getting the following error :- Msg 0, Level 11, State 0, Line 0A severe error occurred on the current command. The results, if any, should be discarded.The query is :- ;with cte as ( select 'Bldgclass' as BldgClass,RuleId,7 As CurVerNum , 'State' As State1 from ERM..RuleConstructionCS where ruleid between 40500001 and 40599999 and SourceCode=29 ) , CTE1 AS ( select GrpAddressID,SourceCode,RuleID,UID FROM ES_Archive..RuletrackerArch where SourceCode=29 and VersionNum=6) ,CTE2 as ( SELECT GrpAddressId,SourceCode,UID FROM CTE A INNER JOIN CTE1 B ON A.RULEID = B.RULEID),CTE3 AS ( SELECT DISTINCT StateCode,UID FROM ES_Archive..EmporisMRSTGMappedArch A INNER JOIN ES_Archive.dbo.tmpCurrMinusPrevGrpAddressId B ON A.GRPAddressID = B.grpAddressID ) SELECT GrpAddressID into abc FROM CTE2 INNER JOIN CTE3 ON CTE2.UID = CTE3.UID Please help me out !!!Regards,Ankit

Discrepancy between sys.master_files and sys.database_files

Posted: 01 Apr 2013 05:19 AM PDT

Hi all,I have discrepancy beetween sys.master_files and sys.database_files in size column. Couple of days ago I changed the size of a log file for one database, however it's not reflected in sys.master_files. Views sys.database_files and sys.sysfiles are OK, they show right value. Is sys.master_files outdated? Should I run some DBCC to update it ?Thanks

Issue with Float datatype while using EXCEPT

Posted: 01 Apr 2013 02:25 AM PDT

I have two tables with float data types and am using EXCEPT to check for the new rows in the source tables.Their is data in the source table but it is returning nulls.I am unable to figure it out , why this is happening.select colmn1, colmn2, -----from table aExcept select colmn1, colmn2from table bnow although talbe A has data but it is giving nullsAny help will be appreciatedThanks

Cardinality Issue

Posted: 01 Apr 2013 02:15 AM PDT

I have a 100,000,000 row table with a GUID primary key. (This is an IBM FileNet/ECM database, and utility query.)The following query:[code="sql"]SELECT TOP 9999 * -- Edited for brevityFROM DocVersion T0WHERE (T0.home_id IS NULL AND ( ( storage_area_id = N'{18CDA09D-00B2-427F-9016-C78844AA92AE}' OR storage_location =N'FNFS:/{18CDA09D-00B2-427F-9016-C78844AA92AE}')) AND (( object_id > N'{42D1BB3B-53F2-462D-A277-1AFF39548364}'))) ORDER BY object_id ASC option (recompile)[/code]is making a cardinality error on object_id. It estimates it will have 10,000 - 20,000 rows on the greater-than comparison, but the actual row count is 46M.Based on this error, it goes for a seek of the primary key, and as such, it takes 4-6 hours to seek 46M times. The scan would be 13 minutes.What I don't understand is 1) Why it is reaching this error, and 2) How to resolve it.The primary key is on the object_id, which is a GUID.This historgram details on the object_id are:[code="plain"]RANGE_HI_KEY RANGE_ROWS EQ_ROWS DISTINCT_RANGE_ROWS AVG_RANGE_ROWS ff4c80d6-98b7-46ef-97f0-[b]0000003c6313[/b] 0 1 0 1 9da7159c-a90e-48e3-84f1-[b]01ef6ded77e4[/b] 319998 1 319998 140b75dcf-55c1-4371-83e5-[b]04b0ea3cea3f[/b] 267887 1 267887 1 e2aed122-0e41-40a2-9296-[b]0ea384fd1a1d[/b] 1608631 1 1608190 1.000275e0fbf953-9a39-4d49-bbc6-[b]132a32003da4[/b] 536035.9 1 536036 1 e9b6e490-233e-40ba-a4e4-[b]19179b42e6c[/b] 5536035.9 1 536036 1 --------------------------------------------------0b8fc800-047f-5eb2-bfb9-[b]1b3e9999571f[/b] 536035.9 1 536036 1 0aa19a05-047f-5eb2-bfb9-[b]1b3e9999571f[/b] 804184.8 1 804094 1.000112(continued...169 steps total)[/code]I believe GUIDs are ordered by the last segment of the guid, and that belief is reflected in this histo. I put a dotted line in the histo: Everything below the line (including the remainding 161 steps) would match the query predicate on object_id.Why in the world does the PK seek think there are only 20k rows? Each step has over 100,000 rows.Thanks for your consideration,@SixStringSQL

Query - Please Help!

Posted: 26 Mar 2013 03:21 AM PDT

Someone please tell me what I'm doing wrong..... :( All I want to do, is get a list of databases which don't have extended properties. Query below:exec ('create table #t_nodb(dbname varchar(120)) insert into #t_nodb (dbname) exec sp_MSforeachdb ''if ''?'' in (''tempDB'') returnuse ? select ''?'' where ''?'' not in (select ''?'' from sys.extended_properties)''select * from #t_nodbdrop table #t_nodb') Thanks!

Duplicating rows based on another table

Posted: 01 Apr 2013 01:51 AM PDT

Hi,I have some data in table a which has a unique identifier called column nd. I have another table, table b, which has that unique identifier, again called nd and another column called j which is a number between 10-20.How can I return the results on table a, but I want a row for each nd times the result in column j where nd is the same in both tables.For example, if nd is equal to small, and j is equal 10 the results from that query would be 10 rows of the word small.Hope that makes sense.Thanks

Why duplicate indexes

Posted: 01 Apr 2013 01:58 AM PDT

It is query logically error, post deleted. Thanks for looking at.

Requirement of .net framework for sql server 2008 r2 in Windows 8

Posted: 01 Apr 2013 12:47 AM PDT

What is the actual version requirement of .net framework for installing sql server 2008 r2 in a windows 8 PC?According to [url=http://www.microsoft.com/en-us/download/details.aspx?id=3743]link [/url]Download and install Microsoft .Net Framework 3.5 SP1. or Download and install Microsoft .Net Framework 4.0.According to [url=http://www.microsoft.com/en-in/download/details.aspx?id=26729]link [/url]Install Microsoft .NET Framework 2.0 or laterIn some article i saw that i should enable .net 3.5 features in control panelSo what is the actual requirement?

Maintenance Plan issue

Posted: 01 Apr 2013 12:21 AM PDT

Hi all, I got a strange issue today. When i am trying to run a maintenance plan manually from GUI. I am not able to execute because the option itself is greyed out.I am interested to know why that execute option is not highlighting.

Monday, April 1, 2013

[SQL Server] importing an excel file

[SQL Server] importing an excel file


importing an excel file

Posted: 01 Apr 2013 12:29 PM PDT

hi professionals.I am trying to import and excel spreadhseet into the database by right clicking the database, tasks, import. I chosen excel as the source and went through the wizard.It goes through all the tasksInitilizing data flow,successInitilizing connections,successSetting SQL command,successSetting source connection,successSetting destination connection,successvalidating,successprepare for execute,successpre-execute,successexecuting,sucesscopy to dbo.SofUseComp (It hangs here)Post executeIt hangs on the copy part of the import wizard, any ideas where I can look to see whats going on. I have imported small files without any problem.This spreadsheet has ten columns and 1,048.576 rowsthanks everyone in advance

query to find timgaps between rows

Posted: 01 Apr 2013 06:52 AM PDT

Basically I want missing timegaps between the @startdate and @enddatewith tbl_book and also in between tbl_book (do not care about the bookid column in the resultset)---------------------------------CREATE TABLE [dbo].[book]( [bookid] [int] IDENTITY(1,1), [starttime] [datetime] NULL, [endtime] [datetime] NULL) ON [PRIMARY]GOINSERT INTO [dbo].[book] ('2013-03-05 16:30:00.000','2013-03-05 16:45:00.000')INSERT INTO [dbo].[book] ('2013-03-05 17:30:00.000','2013-03-05 17:45:00.000') declare @startdate datetime set @startdate='2013-03-05 16:00:00.000' declare @enddate datetime set @enddate='2013-03-05 19:00:00.000'; Resultset may look like:AvailableStart_time AvailableEnd_time---------------------- ----------------------------2013-03-05 16:00:00.000 2013-03-05 16:30:00.0002013-03-05 16:45:00.000 2013-03-05 17:30:00.0002013-03-05 17:45:00.000 2012-03-05 19:00:00.000

on primary

Posted: 31 Mar 2013 10:36 PM PDT

why [b]on primary [/b] is used while creating a table is it necessaryex:create table temp(name varchar(50),age smallint,salary int)[b]on primary[/b]

Search This Blog