Tuesday, April 30, 2013

[SQL server issues] Created Issue: AdventureWorksDW2012 Download file corrupt [19063]

There seams to be an issue with the AdventureWorksDW2012 Data file download. When I try to run this SQL statement:

CREATE DATABASE AdventureWorksDW2012 ON (FILENAME = 'E:\MSSQL11.SQL02\MSSQL\DATA\AdventureWorksDW2012_Data.mdf') FOR ATTACH_REBUILD_LOG;

This is the error I get:

Msg 5172, Level 16, State 15, Line 1
The header for file 'E:\MSSQL11.SQL02\MSSQL\DATA\AdventureWorksDW2012_Data.mdf' is not a valid database file header. The FILE SIZE property is incorrect.

Thanks,Dan

There seams to be an issue with the AdventureWorksDW2012 Data file download. When I try to run this SQL statement:

CREATE DATABASE AdventureWorksDW2012 ON (FILENAME = 'E:\MSSQL11.SQL02\MSSQL\DATA\AdventureWorksDW2012_Data.mdf') FOR ATTACH_REBUILD_LOG;

This is the error I get:

Msg 5172, Level 16, State 15, Line 1
The header for file 'E:\MSSQL11.SQL02\MSSQL\DATA\AdventureWorksDW2012_Data.mdf' is not a valid database file header. The FILE SIZE property is incorrect.

Thanks,Dan


.

sqlserversamples.codeplex.com

[MS SQL Server] reporting server, separate or not

[MS SQL Server] reporting server, separate or not


reporting server, separate or not

Posted: 30 Apr 2013 04:25 AM PDT

I would like to know from other DBAs, how do you setup your reporting server, you use a seperate server or on the same database server that has the data source for the reports?In our environment, we intall database servers and SSIS on the same server, and install reporting service on a separate server (with database engines too, but it only hosts reportdb, and tempreportdb) for at that time reporting service is using IIS, so we think it is good to separate them because performance and security.Now we are upgrading it to SQL 2008 R2, which will not use IIS for reporting server any more, I wonder [b]if it is good[/b] to install all - db engine, ssis, ssrs on one box, this will save a hardware, but not sure if this will affect performance or others.Thanks,

Avamar Transaction Log Backup Issue

Posted: 04 Feb 2013 01:34 AM PST

Hi,We just recently started using Avamar to backup everything including an hourly SQL server transaction log backup. The issue we're having is that since we started using Avamar, the transaction file (LDF) file keeps growing very large. Has anyone experienced this issue before? If not, any idea?Thanks,

Help with a Deadlock Issue

Posted: 29 Apr 2013 06:42 AM PDT

Recently we have started seeing some deadlocks reported on a database instance. I have enabled the trace -T1222 and am trying to interpret what has been returned in the logs : (the actual queries are quite lengthy)Spid 161 is running this query (line 14 of proc [1]): SELECT ...... from table1 .....Spid 98 is running this query (adhoc line 1 of proc [p2]): UPDATE .....from table1Spid 161 is waiting for a Shared page lock on index table1.idx1. (Spid 98 holds a conflicting IX lock.)Spid 98 is waiting for an (IX page lock on index table1.idx2. (Spid 161 holds a conflicting Shared lock.)Just after some advice on what I can look at to resolve the deadlock. My hands are a bit tied as the update command is being called by a suppliers application and this and the underlying tables cant be altered.The Select command is an in house process that we can look at changing but I'm not sure what can be done to the select statement to stop the lock. I have seen the NOLOCK table hint but I'm a little reluctant to suggest this as a solution.Thanks for any helpFrant101

Advice in restore and backup check schedule

Posted: 29 Apr 2013 07:29 AM PDT

Ok,We all know how important to check (and restore) your backup file is, right? ;-) ... so I am trying to follow that good practice without making it an impossible task. (I have hundreds of databases assigned to me, space and time is limited)So my question would be, or more kind of a poll question, what schedule do you use? Here's what I am trying to implement. -Weekly check (Sundays): critical clients or anything above 100GB-Monthly check(Sundays): anything lower than 100GB or any other client.I am using RedGate 7.0 which allows me, as part as the regular check, do the following:-Grab backup file from backup repository using Scheduled Restore feature-Restore database-Run DBCC-Delete if everything went fine-Send email informingFor the Weekly checks, I was planning to start those at 2am, 4am, 6am, and so on. Now, the Monthly checks is what confuses me. I was planning to do that randomly, but how should I schedule those?Any hints? :rolleyes:By the way, the SQL instance I am using is not a production box. So does not running anything critical. However, I prefer to restore and check weekends, so it will not make it too slow (it's a VMware machine)Any suggestion is highly appreciated

Hidden job keep on failing every 2 minutes with sql server agent account on mirror side

Posted: 29 Apr 2013 07:06 AM PDT

HI,I am unable to find the job keep on failing job on mirroring side in every 2 minutes with sql server agent account,I am not seeing any scheduled jobs in sql server agent..If you guys have any idea about to troubleshooting..plz help me...

SSMS very laggy when typing a query

Posted: 29 Apr 2013 05:50 AM PDT

This is a strange one. I am typing a query in SQL Server Management Studio. Nothing is executing on the server. I actually get an hourglass as I type the query at which point I am forced to wait up to 10 seconds before I can type again. I may get one word typed before I get another hourglass.I tried to RDP to the server directly (thinking it may be something on my computer) and the problem happened there as well. I did a task manager and all the processors were maxed out and the memory usage was maxed as well. SSMS was using 100% of the server. Again, nothing was executing. Any ideas?

[Articles] Most important DBA Skill?

[Articles] Most important DBA Skill?


Most important DBA Skill?

Posted: 29 Apr 2013 11:00 PM PDT

What is the most important DBA Skill?

[SQL Server Data Warehousing] Data warehouse


We have constructed the data warehouse  in SQL Server -> creating dimensions, fact tables. Its not relational database(have not added primary key or surrogate key) in the data warehouse.


Our functional area is Terminal & Ports, so is this right approach to have the non relation database or not?


Should we go with Normalization approach or dimensional?



.

social.technet.microsoft.com/Forums

[T-SQL] Parent/Child and Recursion

[T-SQL] Parent/Child and Recursion


Parent/Child and Recursion

Posted: 29 Apr 2013 11:12 PM PDT

I have data in a table like this:[b]Parent[u][/u][/b] [b]Child[u][/u][/b]300001 110081300001 102157300001 102158300001 102159110081 101000110081 101504110081 102129Child 110081 of parent 300001 has children 101000, 101504, and 102129.I need a query that returns this result:[b]Parent[u][/u][/b] [b]Child[u][/u][/b]300001 101000300001 101504300001 102129300001 102157300001 102158300001 102159 I've tried a recursive CTE without success. Table values are in varchar format. Help Please?

T-SQL Greatest function workarounds - timing tests

Posted: 29 Apr 2013 09:13 AM PDT

So, I find myself in need of a GREATEST function equivalent, and I want to make sure before I best practice this concept in my head I do some functional testing. I've created a test bed and I'm getting similar results on the systems I've tested.It requires 2k8 to try the workarounds because they're based off the CROSS APPLY.Now, as a baseline, I've built the Case statement from heck, and a million row test structure. My results before you get to the code look like so:[code="plain"]TestType AvgLen MaxLen MinLen--------------- ----------- ----------- -----------Cascade Test 2152 2946 1713CASE Test 1889 2356 1506Values Test 1027 1433 833[/code]That said, I'd like some of the folks here to take a look at the process, if you're willing, and see what you can break in it. From what I can tell, a VALUES build is running at about twice the speed as any other alternatives I've come up with. The iTVF wasn't worth discussing when I timing tested it. It came in at about the same level as the Cascade, for similar reasons. You have to embed the function in the function to get it to work right and it just became a mess.UNPIVOT is right out. Because of the need in my scenario to alter what values are included, it became overly complex for maintenance. If someone has a clean way of performing it, I'd be interested. This test is simplified from my business case, but it has all the moving parts.So, the test harness:[code="sql"]IF OBJECT_ID ('tempdb..#blah') IS NOT NULL DROP TABLE #blahIF OBJECT_ID ('tempdb..#dump1') IS NOT NULL DROP TABLE #dump1IF OBJECT_ID ('tempdb..#dump2') IS NOT NULL DROP TABLE #dump2IF OBJECT_ID ('tempdb..#dump3') IS NOT NULL DROP TABLE #dump3IF OBJECT_ID ('tempdb..#results') IS NOT NULL DROP TABLE #resultsCREATE TABLE #blah ( RowNum INT IDENTITY(1,1), Date1 DATETIME, Date2 DATETIME, Date3 DATETIME, Date4_1 DATETIME, Date4_2 DATETIME, Date4_3 DATETIME )CREATE CLUSTERED INDEX idx_c_Blah ON #Blah ( RowNum)CREATE TABLE #dump1 (RowNum INT, MaxDT DATETIME)CREATE TABLE #dump2 (RowNum INT, MaxDT DATETIME)CREATE TABLE #dump3 (RowNum INT, MaxDT DATETIME)CREATE TABLE #results (TestType VARCHAR(15), MillisecondLength INT );WITH cteTally AS ( SELECT TOP 1000000 ROW_NUMBER() OVER(ORDER BY sc1.Type) AS N FROM sys.syscolumns sc1, sys.syscolumns sc2, sys.syscolumns sc3 )INSERT INTO #blahSELECT -- N, GETDATE(), GETDATE() + 1, GETDATE() - 1, GETDATE() + 2, GETDATE() + 3, GETDATE() + 4FROM cteTally-------------- End Structure Build ------------------GODECLARE @StartTestTime DATETIMETRUNCATE TABLE #dump1TRUNCATE TABLE #dump2TRUNCATE TABLE #dump3-- Did you know that discard results in options in 2k8R2 actually dumps the statistics in messages, too?-- Yeah, I didn't either until just now...--SET STATISTICS TIME, IO ONSET @StartTestTime = GETDATE()-- Values GREATEST --INSERT INTO #dump1SELECT RowNum, drv.MaxDtFROM #blah CROSS APPLY (SELECT MAX( dt) AS MaxDt FROM ( VALUES ( Date1), (Date2), (Date3), (CASE RowNum %4 WHEN 1 THEN Date4_1 WHEN 2 THEN Date4_2 WHEN 3 THEN Date4_3 WHEN 0 THEN '19000101' END) ) ValueList (dt) ) AS drvINSERT INTO #results VALUES ( 'Values Test', DATEDIFF( ms, @StartTestTime, GETDATE()))SET @StartTestTime = GETDATE()-- Cascading CrossApply GREATEST --INSERT INTO #dump2SELECT RowNum, ca3.GrtDt3FROM #blah AS b CROSS APPLY ( SELECT CASE WHEN b.Date1 >= b.Date2 THEN Date1 ELSE b.Date2 END AS GrtDt1) AS ca CROSS APPLY ( SELECT CASE WHEN ca.GrtDt1 >= b.Date3 THEN ca.GrtDt1 ELSE b.Date3 END AS GrtDt2) AS ca2 CROSS APPLY ( SELECT CASE WHEN ca2.GrtDt2 >= CASE b.RowNum %4 WHEN 1 THEN b.Date4_1 WHEN 2 THEN b.Date4_2 WHEN 3 THEN b.Date4_3 WHEN 0 THEN '19000101' END THEN ca2.GrtDt2 ELSE CASE b.RowNum %4 WHEN 1 THEN b.Date4_1 WHEN 2 THEN b.Date4_2 WHEN 3 THEN b.Date4_3 WHEN 0 THEN '19000101' END END AS GrtDt3 ) AS ca3INSERT INTO #results VALUES ( 'Cascade Test', DATEDIFF( ms, @StartTestTime, GETDATE()))SET @StartTestTime = GETDATE()-- CASE method GREATEST --INSERT INTO #dump3 SELECT RowNum, CASE WHEN Date1 >= Date2 THEN CASE WHEN Date1 >= Date3 THEN CASE WHEN Date1 >= CASE RowNum %4 WHEN 1 THEN Date4_1 WHEN 2 THEN Date4_2 WHEN 3 THEN Date4_3 WHEN 0 THEN '19000101' END THEN Date1 ELSE CASE RowNum %4 WHEN 1 THEN Date4_1 WHEN 2 THEN Date4_2 WHEN 3 THEN Date4_3 WHEN 0 THEN '19000101' END END ELSE CASE WHEN Date3 >= CASE RowNum %4 WHEN 1 THEN Date4_1 WHEN 2 THEN Date4_2 WHEN 3 THEN Date4_3 WHEN 0 THEN '19000101' END THEN Date3 ELSE CASE RowNum %4 WHEN 1 THEN Date4_1 WHEN 2 THEN Date4_2 WHEN 3 THEN Date4_3 WHEN 0 THEN '19000101' END END END ELSE CASE WHEN Date2 >= Date3 THEN CASE WHEN Date2 >= CASE RowNum %4 WHEN 1 THEN Date4_1 WHEN 2 THEN Date4_2 WHEN 3 THEN Date4_3 WHEN 0 THEN '19000101' END THEN Date2 ELSE CASE RowNum %4 WHEN 1 THEN Date4_1 WHEN 2 THEN Date4_2 WHEN 3 THEN Date4_3 WHEN 0 THEN '19000101' END END ELSE CASE WHEN Date3 >= CASE RowNum %4 WHEN 1 THEN Date4_1 WHEN 2 THEN Date4_2 WHEN 3 THEN Date4_3 WHEN 0 THEN '19000101' END THEN Date3 ELSE CASE RowNum %4 WHEN 1 THEN Date4_1 WHEN 2 THEN Date4_2 WHEN 3 THEN Date4_3 WHEN 0 THEN '19000101' END END END ENDFROM #blahINSERT INTO #results VALUES ( 'CASE Test', DATEDIFF( ms, @StartTestTime, GETDATE()))SET @StartTestTime = GETDATE()--SET STATISTICS TIME, IO OFFGO 50SELECT TestType, AVG( MillisecondLength) AS AvgLen, MAX( MillisecondLength) AS MaxLen, MIN( MillisecondLength) AS MinLenFROM #resultsGROUP BY TestTypeGO[/code]As I mentioned, I'd be appreciative if some of y'all would be willing to run this and check if you get similar times, and see if you can find exceptions to the timings due to some wildness I haven't even contemplated yet.

Stuck with a getdate time range?

Posted: 29 Apr 2013 09:22 PM PDT

Hi All, Sorry if this has been asked somewhere all ready but I've struggled to find the answer! I have a date time field which is a date time stamp on activity. i need to have a query that only brings back information for data that's between today's date and events between 08:00 and 10:00, but i need the date to be dynamic, so that it always returns today's date with that between those times.My brains says it should be straight forward but i cant suss it.Thanks

creating table error?

Posted: 29 Apr 2013 06:52 PM PDT

Hai Friends, Im creating one table for web application these is my table structure.after wrote the code ll show one waring messagecreate table onward_journey(onward_journey int identity,departuredate datetime,from_location varchar(100),to_location varchar(100),metro nvarchar(1100),trans_all nvarchar (1100),mode_of_travel nvarchar(1100),seat_type nvarchar(1100),no_of_days int,other_details varchar(100),status_id int foreign key references status(status_id))Warning: The table 'onward_journey' has been created but its maximum row size (9156) exceeds the maximum number of bytes per row (8060). INSERT or UPDATE of a row in this table will fail if the resulting row length exceeds 8060 bytes.do the need full what can i do now?

How to pass where condition as parameter of stored procedure

Posted: 29 Apr 2013 02:26 PM PDT

How to pass where condition as parameter of stored procedure

How To Avoid The Duplicate Records....

Posted: 29 Apr 2013 04:39 AM PDT

Hi Friends...I Having Table For The Following Structure..[code="sql"]create Table EmployeeDet (EmpID int,EmpName Varchar(100),Department varchar(100),Age int,salary int)insert into EmployeeDet values (1,'Arun','Accounts',25,25000),(1,'Arun','Accounts',23,21000),(1,'Arun','Accounts',26,22000),(1,'Arun','Accounts',29,27000)insert into EmployeeDet values (2,'kumar','Production',23,18000),(2,'kumar','Production',27,30000),(2,'kumar','Production',31,19000)insert into EmployeeDet values (3,'saran','Sales',22,38000)insert into EmployeeDet values (4,'Vidya','Purchase',18,20000),(4,'Vidya','Purchase',27,36000),(4,'Vidya','Purchase',23,35000)select * from EmployeeDetEmpID EmpName Department Age salary1 Arun Accounts 25 250001 Arun Accounts 23 210001 Arun Accounts 26 220001 Arun Accounts 29 270002 kumar Production 23 180002 kumar Production 27 300002 kumar Production 31 190003 saran Sales 22 380004 Vidya Purchase 18 200004 Vidya Purchase 27 360004 Vidya Purchase 23 35000Below I have mentioned The my Required Table Data EmpID EmpName Department Age salary1 Arun Accounts 25 250002 kumar Production 23 180003 saran Sales 22 380004 Vidya Purchase 18 20000[/code][u]My Requirement :[/u]1) EmpID,EmpName,Department Field Should not be Duplicate Record...2) You Take First Record or Last Record or Middle Record of the Particular EmpID but EmpID,EmpName,Department Should be Unique... ( Here I Mentioned First Record of The EmpID )...Thanks & Regards,Saravanan.D

No result set

Posted: 29 Apr 2013 05:46 AM PDT

I have this query:declare @controlnumber varchar(13) set @controlnumber = '0210300000001'select *from Cards where controlNum like ''''+SUBSTRING(@controlnumber,1,5)+'%'+''''it returned nothinghowever if I change the where clause to controlnum like '02103%' then it worked. Did I miss a quote or something?thanks for all the help and advice.

Stored Proc Novice Help

Posted: 29 Apr 2013 02:58 AM PDT

Hi all,I'd be really grateful if someone could help me (probably something very basic I'm missing!)I'm trying to create a stored procedure (code below) but it's failing. If I execute the create table, insert into, select and drop statements as a batch the code runs perfectly but when I put it in a create proc statement it fails!! Can anyone help please?[code="sql"]use tempdbgocreate proc dbo.DailyDBSizeCheckas create table #DatabaseSize ( fileid int, groupid int, size int, maxsize int, growth int, status int, perf int, name varchar(50), filename varchar(100) ) go insert into #DatabaseSize exec sp_msforeachdb @command1='select * from ?..sysfiles;' go select name as [DB File Name], filename as [DB File Path], size*8/1024 as [DB Size (MB)] from #DatabaseSize go drop table #DatabaseSize go[/code]

[SQL Server] Using REPLACE in an UPDATE statement



Weekly SQL Server newsletter with articles, forum posts, and blog posts via email. Subscribers receive our white paper with performance tips for developers.



SQLTeam.com Articles via RSS


SQLTeam.com Weblog via RSS



.

sqlteam.com

[SQL Server] Using Dynamic SQL in Stored Procedures



Weekly SQL Server newsletter with articles, forum posts, and blog posts via email. Subscribers receive our white paper with performance tips for developers.



SQLTeam.com Articles via RSS


SQLTeam.com Weblog via RSS



.

sqlteam.com

Search This Blog