« first day (1864 days earlier)      last day (3004 days later) » 

 
1 hour later…
8:08 AM
Morning
@swasheck thanks for your input yesterday
 
morning
 
Haha, I'm reading Aaron's blog post about the VS outage ;)
> And I do sincerely hope they fix those object names – why a table needs a tbl prefix is beyond me.
identity is reserved. They had to use tbl_identity ;)
 
8:25 AM
Please give me 15 minutes before closing this
0
Q: data warehouse automation tool: benefit or bane?

mg1075Today while investigating ETL and data warehouse solutions like Kettle, I came across a new concept (for me) called data warehouse automation tool. I also looked at the white paper here, which indicates there are few vendors in this space. One reaction I have to these tools is: whoa, anyone p...

I'd like to weigh in a second opinion to avoid the vendor position ending up the only truth
 
@TomV You could post a stub, delete, edit, undelete.
 
@AndriyM Ah, good idea
 
@TomV Why? Seems like a valid question to me.
Did I miss something?
 
8:44 AM
@ypercubeᵀᴹ If only the fact that four people have voted to close it as primarily opinion-based :)
I'm one of those four, as it happens. And if I hadn't chosen "opinion-based", I'd've probably ended up choosing "too broad".
 
@ypercubeᵀᴹ I think it's a 50/50 but given that I noticed close votes rising while I was thinking about answering it made me realize that it could have been closed by the time I finished typing
 
Good morning, Heapsters. If you're bored at work or in a reading mood, I would love some feedback on my new post on creating a T-SQL function for calculating medians.
 
9:08 AM
@DanielHutmacher Nice!
 
@DanielHutmacher You can do that in SQL 2016 with R now look : ) Not to say you should of course ...
 
Have you done any performance tests, to compare against the OFFSET/FETCH and the PERCENTILE_CONT methods?
 
@ypercubeᵀᴹ Itzik did, and the OFFSET-FETCH was a bit quicker if memory serves. I think it came down to whether the data was high or low density (few groups with a lot of rows vs many groups with few rows). I'll run some tests.
 
@ypercubeᵀᴹ Aaron did on this post. sqlperformance.com/2012/08/t-sql-queries/median PERCENTILE_CONT runs like a three legged dog
 
@MarkSinkinson I'm reading that, just now.
 
9:14 AM
@wBob yikes. I'm still too scared (and statistically challenged) to do anything with R, but that'll probably change sometime around 2029 when my customers are on SQL Server 2016...
 
@DanielHutmacher lol feel your pain. It would be interesting to do some perf testing with it. I wouldn't expect it to do that well but worth a look. Now to find the time ...
 
Hello and good morning. Basically I have 2 questions which one relates to the other.
1) Does `select top 5 * from T` actually translated to `order by pk` ? and if not , so `order by` what?
2)Will SQL server puts more effort with `select top 5 * from T order by PK desc` than `select top 5 * from T`?
 
@RoyiNamir 1) No. It's ORDER BY "whatever you like";
 
So what is the order by that SQL provides result with ?
( I didnt specify "whatever you like")
 
@RoyiNamir Whatever happens to be the output of the best plan he could come up with satisfying your requirements (which don't include a sort)
 
9:28 AM
@RoyiNamir "Whatever SQL Server likes at the moment you run the query"
 
@RoyiNamir, assuming you're just selecting from a single table, in most cases the query will use the order of the clustered index (or heap) that the table is stored in, but this is not guaranteed. <guesswork> Sometimes, like with fragmented clustered indexes, SQL Server may find it quicker to just read the physical storage order from the drive (as opposed to the order of the index pages), in which case you will get a random-like order. </guesswork>.
For short, if you don't specify ORDER BY, the output is not ordered.
 
TOP without ORDER BY says "get me 5 rows, I don't care which"
 
Thanks. Regarding the second question ( pedant POV) : Will it take more time to run :
`select top 5 * from T order by ClusteredIndexColumn desc` VS `select top 5 * from T order by ClusteredIndexColumn asc` ? I mean : the first query should SORT IT DESC and THEN yields 5 results , while in the second query , it is already ordered ( clustered index) so all it has to do is yield 5 first records.
Am I right?
(or is it really smart and the data can be read straight from end to start)
 
No, the plan is the same, the difference is whether the scan goes forward or backward.
Try both queries in SSMS, view the estimated query plan (Ctrl+L). If you hover over the Clustered Index Scan operator, you'll see Ordered: True. If you hover over the arrow just after the Scan, before the Top operator, it'll estimate 5 rows.
 
9:43 AM
Since you are saying deadlocks are canceled by restarting, are you confusing locks with deadlocks? deadlocks are resolved by the engine pretty quickly — Tom V 21 secs ago
 
Backwards scans can't parallelise, interestingly enough.
 
Happens all the time with our developers and I hate it
 
@DanielHutmacher I just tried that. ( actual execution plan). But what is the meaning of "estimated number of rows" ? AFAIK , the REQUEST operators are from left to right. So TOP is asking row by row from the Clustered index Scan and that , in turn , yielding row by row. so where is the estimation here?
 
@MarkSinkinson , @DanielHutmacher I have an alternative query (that uses PERCENTILE_CONT). See in the SQLfiddle. @AaronBertrand you may be interested to compare against your (2012+2). I tried in SQLfiddle but I guess even 1k rows is too much for it and I get errors.
 
@RoyiNamir Exactly. The Top operator tells the Scan operator five times to send one row, and in which order.
@ypercubeᵀᴹ Curious! Will check.
 
9:58 AM
@DanielHutmacher Yes , but if it asks 5 times , then why does it shows : "Estimated Number of rows?" it suppose to show only "ACtual number of rows". I don't see why estimation is needed when it knows exactly how many times it requested a row.
 
@RoyiNamir You could have less than five rows in the table, I suppose. :)
 
@ypercubeᵀᴹ Not sure if SQL Fiddle just doesn't like me, but I can only see the Schema pane completed
 
@MarkSinkinson Yah, I get errors, too. Here is the query:
SELECT d.SalesPerson, m.Median
FROM
    ( SELECT DISTINCT SalesPerson FROM dbo.Sales ) AS d
  OUTER APPLY
    ( SELECT TOP (1) Median = PERCENTILE_CONT(0.5) WITHIN GROUP
             (ORDER BY Amount) OVER ()
      FROM dbo.Sales
      WHERE SalesPerson = d.SalesPerson
    ) AS m ;
(and yeah, it has TOP without ORDER BY ;) @RoyiNamir
 
:-)
 
10:18 AM
@ypercubeᵀᴹ It's appears to be a little faster at lower volumes, but once you start to scale then the standard PERCENTILE_CONT is faster
 
@MarkSinkinson Thnx! I guess you tried with the NCI index as Aaron's blog? ON dbo.Sales(SalesPerson, Amount)
 
10:34 AM
@ypercubeᵀᴹ I used the schema from the Fiddle with that NCI
 
@MarkSinkinson Great thnx. I had some hope that the "group by first, then outer apply" might be more efficient than the "percentile first, then group by" :(
 
@ypercubeᵀᴹ Someone better at doing performance comparisons may have more useful results. Plus we're only running Microsoft SQL Server 2012 - 11.0.5058.0
 
 
2 hours later…
12:16 PM
-1
Q: I want to write query as per business requirement

AnandUniverse Addition for Historic Data: Expired Contact Company Associations with companies as defined in universe, provided the record has either Committee or Compensation info, and belongs to Company which is tagged to index-either Russell3000 or S&P500. (Index will be added incrementally here, ...

no you don't, you want us to write a query as per your business requirement
 
1:12 PM
@TomV I was expecting him to edit the query once he said he would provide the information...
 
0
Q: Equalize datafile size

WoozieBEI have a DB (Microsoft SQL server 2008 R2 (10.50.1600.1)) that has 28 datafiles with all different filesize. Some are 10GB, some 15GB, some 27 GB, etc. The difference in filesize is a historical fact. Different DB managers, forgotten autogrowth options, max size, ... My question is, how can I equ...

Is this worth reopening?
 
1:38 PM
@MarkSinkinson I hope, his previous questions didn't really turn out well
 
1:55 PM
Somehow he fluked a +14 on a question. Probably felt like a god after that...
 
@ypercubeᵀᴹ I think it's an interesting problem but may need some more information about spaceused and things like that in each file
 
@TomV What would the solution be? Backup the db and restore to 10GB size files?
 
I'm not sure, that's why I'm interested in the possible solutions (which I hope I'll never need)
Can you add more details about what's in the data files? Is there enough empty space in them to perform the downsizing or does data need to be migrated between files before they can be evened out? Also, any reason you want to keep multiple files and not have everything consolidated in one file? — Tom V 10 secs ago
 
2:43 PM
@RoyiNamir If you don't specify ORDER BY, SQL Server will assume you don't care about order. It will pick what it thinks is most efficient, and that can change the next time you run the query, and again the time after that, and so on. It's dangerous to make assumptions about what you observe once, because that won't necessarily happen every time - see #3 here.
4
@ypercubeᵀᴹ Pretty similar. Yours does a few more reads.
@ypercubeᵀᴹ In cases where the performance differences are negligible, I would tend to write it in the clearer way, unless I knew of any cases where the less intuitive form was markedly better.
@DanielHutmacher A couple of good posts from Paul White here too. sqlperformance.com/?s=median&searchsubmit=
@ypercubeᵀᴹ And in this case, OFFSET/FETCH still beats both of those approaches.
 
 
1 hour later…
4:04 PM
I think I don't understand this:
@dezso Yeah, kinda, I want to prevent an OS user from logging into databasea and allow them to log into databaseb as a different OS user. — Everlight 14 mins ago
 
@TomV i dont think i did much of anything, just stated the obvious
 
4:23 PM
@AaronBertrand I run into this constantly. "Well I did an ORDER BY when I put it into the table so it should come out the same way derp derp it seems to whenever I look at it derpy derp"
2
Luckily I've got a good example to prove that assumption to be incorrect.
 
5:05 PM
@ypercubeᵀᴹ It's decidedly a much clearer question now.
 
5:21 PM
@TomV My pleasure. Seeing things from a different perspective (and less "entangled", in this case) can be quite helpful in solving a problem.
 
6:03 PM
> I did google and found out some weird keywords LEFT, JOIN but I couldn't understand it.
0
Q: Selecting data from another table using a foregin key

YashasI have two tables A & B. Table A: id | name | num Table B: id | date | roll id in table B is a foreign key which relates to the id in table A. I want to get the contents of table B where id is given and also along with that data, I need the name whose id is given from table A. I did google ...

@AaronBertrand thnx !
 
@ypercubeᵀᴹ Sure. Time is irrelevant with such small tables, but the I/O numbers are quite telling.
 
6:43 PM
Did anyone else get notifications about unusual logons to their MSDN/Technet/Microsoft accounts today?
 
@ypercubeᵀᴹ yikes
@JamesLupolt let me see
 
@JamesLupolt i was trying to guess your password. i needed some download media
 
@swasheck Cool. I see you are in Hong Kong
 
@JamesLupolt nope
 
jlupolt@theheap.com ... ILove1Dir3ction!!! was an easy password to guess
 
6:57 PM
That's the other jlupolt
Thanks for checking
 
@swasheck Oh but that was useful anyway
the obvious could have been "you are insane, step away from the database server before TerriBad things happen"
 
not likely
 
@MDCCL I've never been good with theory myself and I've seen many real life cases where pulling people away from the theory into the real world helps them grasp things. I think it's sort of a tunnel vision one needs to get out
 
Celko is that way - he doesn't understand for example why Amazon might need a surrogate key for anything
In a textbook, every customer has a "natural key" - in real life, not so much.
 
Yes, the world is one big "it depends" unless it comes to math
 
7:07 PM
Some people read Celko's stuff and mistakenly think he's representative of how database specialists think in general
 
@AaronBertrand i used to actually feel generally dirty when i even considered a surrogate key. now i realize their utility. it was an artifact of much textbookery
 
Why?
They're extremely useful.
 
i know ... sorry ... allow me to clarify
 
I think the Neo4j CTO did a presentation where he uses Celko as an example of how arrogant he thinks DBAs are
 
Celko is a DBA like I am a neurosurgeon
 
7:09 PM
sometimes brain surgery seems straightforward compared to requirements gathering
 
Celco is a mathematician, QED
 
I've never heard of this fella
 
Joe Celko, helped write several of the first ANSI SQL standards
 
So says his bio.
 
If you think I'm pompous, and ornery toward dumbness, you should search for some of his Usenet threads
 
7:12 PM
It also says "and he is famous for his his dry wit." Which seems like an odd thing to mention even if it is true.
 
mostly known for his cuff links though :)
 
apparently @AaronBertrand is Miss Congeniality compared to him
@Zane "dry wit" = "being a dickback"
at least that's what people say about me
 
He's my prototypical example of Jeckyll/Hyde - total asshole online, and super nice modest person in person
 
I didn't know he was nice in person
He's entertaining, often helpful, and very hostile and unpleasant online.
Are his books worth reading?
 
Is he still active online by the way? Been ages since I heard anybody mention him
 
@TomV clearly just skating by on reputation
 
Yeah I think he contributes on SSC occasionally
Here is an actual story about his attitude in person (I have no idea why the pictures aren't showing up)
 
@AaronBertrand looks like he was drunk posting
 
@AaronBertrand too late I already read it!
 
> DNS Request Blocked

The web page you were trying to visit has been identified as malicious and has been blocked in accordance with company policy.
BAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAH
 
7:18 PM
@swasheck oh that actually came up today on twitter
 
just sent an email to our helpdesk. "aaron's not malicious, just misunderstood"
3
 
Bing ballwashed us
.@vestergaardj @sqlblog @bing FYI this is happening for all links to sqlblog . com /cc @AdamMachanic https://t.co/hdqzbWh5Rl
 
@AaronBertrand yeah. sqlblog and aaronbertrand.com is also getting blacklisted internally
 
I feel that without seeing the TShirt I can't really grasp the joke.
 
@swasheck Latter is my bad, I let the domain expire because the renewal went to junk. Squatter bought it up.
 
7:20 PM
@AaronBertrand ah. well. that's where the picture source is redirecting
 
I'm getting warnings from System Center Endpoint Protection when I visit sqlblog too
 
which is why they're not appearing
 
On that one I agree with him, but I don't castrate users for it.
 
re the security warnings: Advertising network distributing crap?
 
@TomV sqlblog is hosted on an old-ass piece of junk platform, IIRC. maybe "community server" has been compromised
:D
 
7:24 PM
Seriously? Are they running that? Community server is compromised by default
BBL, i'll be posting some unicode fun or javascript injection over there :)
Ah the fun we had over at thedailywtf.com
 
For some reason SQL Sentry is trying to display on a monitor that I'm not connected too.
.....
 
@TomV I was thinking spam comment crap got through, those things are set up to link to all kinds of nefarious things
@Zane I think that's a Windows issue, we just go where Windows tells us to go.
 
I hate our computers here so much.
It is
I left it up and now it won't recenter until I go home and have that set up
 
@AaronBertrand Bing filters you because you make microsoft's documentation look... lacking
 
 
1 hour later…
8:44 PM
Anyone know off hand why using update '' on an int value would equate to a 0 in the table?
 
@Zane why yes!
17
A: Why 0 is equal to empty string?

Tom VThat is just documented behavior. I don't think anyone messed with the settings. See data type precedence on MSDN. When an operator combines two expressions of different data types, the rules for data type precedence specify that the data type with the lower precedence is converted to th...

 
thank you
How peculiar.
 
10 flags! That must be a record (but not a row).
 
I understand how this works. I just don't understand why '' equals 0 or 1/1/1900'
 
See the comments moved to chat, it might not be logical but it's how it works
 
8:55 PM
Glad to see I'm not the only one who feels that logically that behavior is bonkers.
 
The behavior is really stupid. Arbitrary token values for the win.
 
^^Exactly
 
However, it's also why we can save some typing with DECLARE @f_me DATETIME = DATEDIFF(DAY, 0, GETDATE());
Instead of the 6 hours it would take to type '19000101'
(A shortcut I used to use quite readily, I'll admit)
 
Saves you from a fat finger error I suppose.
 
9:01 PM
It's going to be another go immediately to the bar kind of day.
 
@AaronBertrand what i really hate is the subtraction of an integer from a date. it's unnerving to me
> select getdate() - 1
fortunately that's broken with datetime2
 
Thankfully that won't work with Date/Datetime2
 
ah. date, too
@Zane it's just one of those days?
 
@swasheck yup
 
@Zane do you pack a chainsaw?
 
9:06 PM
Getting a lot of frustrating conversations.
 
select getdate() - 'hope this works'
 
Remember that time before we had CAST(GETDATE() AS date)? This little gem of clarity and readability: SELECT CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) :)
3
 
9:21 PM
Anyone know if 0xDBE and DataGrip are the same product or completely different?
@DanielHutmacher those conversions always made me especially stabby
 
Ah, so yes, same product, thanks
 
@AndriyM 1 sec faster than me
 
Different, but serious question. Someone says "here is your contract, it's a Word document, please sign and return to me." What do you do?
 
@dezso I guess I had fewer things to do :)
 
9:25 PM
I suppose I could take a screen shot of the signature page, print it out, sign my name on the paper, take a picture of that with my phone, e-mail it to myself, then copy and paste the attachment into the Word doc...
 
@DanielHutmacher unfortunately yes
 
@AaronBertrand sign and scan
 
Yeah because of all the scanners on my desk
 
@AaronBertrand don't forget to convert it to jpeg first, then edit a few times, while setting a low quality
 
i think that's what they expect of you ... but yeah
 
9:26 PM
It's not 1994 man
 
@AndriyM that's next to impossible
 
Do you think I can just type my name where it asks for signature?
 
GIVE IT A TRY!
 
ok thanks guys
 
@swasheck !!
 
9:27 PM
I don't know why I ever ask any questions elsewhere
I mean all the answers are right here
 
we're here to halp
 
^^ those were missing
 
@dezso so sorry
 
WHAT DO YOU KNOW, MY CURSIVE IS PERFECT ARIAL
And here, I can do Verdana, too: Aaron Bertrand
 
@TomV @DanielHutmacher I still see that pattern in Tableau queries. I'm not sure if it's the user or if Tableau is generating it.
 
9:29 PM
@AaronBertrand you should have done Comic Sans.
 
That font is a virus
 
"Can you scan and send me that?" "No, because of where I live." "Where do you live?" "2016." - read it somewhere on the global interwebs.
3
 
@AaronBertrand periodically i come across an MSDN blog post with code in Comic Sans
i dont know if i should laugh, cry, trust, mistrust
 
@swasheck I have thankfully not seen that. Next time you see that try to remember to send me the URL.
Funny April Fools' joke too, you can change the default display font in the browser to be Comic Sans, now that will be used for any text that isn't explicitly styled. Most people will just think a lot of web designers have gotten stupid(er).
 
9:33 PM
I thought only Erland Sommarskog uses the default font nowadays?
 
oh thank you very much
gone to change my training presentations
 
In case you’ve been missing Comic Sans, sometimes you can find Microsoft blog posts that use it for sample code : https://blogs.msdn.microsoft.com/sqlserverstorageengine/2016/01/10/clustered-columnstore-index-data-load-optimizations-minimal-logging/
 
@AaronBertrand oh now you've done it
 
@AaronBertrand ha, it's a completely sane font here (except that it's not fixed width)
the small advantages of being on linux
 
9:40 PM
or of uninstalling Comic Sans
 

« first day (1864 days earlier)      last day (3004 days later) »