SQL-Server-First-Responder-Kit icon indicating copy to clipboard operation
SQL-Server-First-Responder-Kit copied to clipboard

sp_BlitzFirst - create schema specified in @OutputSchemaName if it doesn't exist

Open BrentOzar opened this issue 10 years ago • 7 comments

From Andy Schwabe:

sp_AskBrent @OutputSchemaName doesn't create a schema if it doesn't exist. Since AskBrent is more than fine with creating tables if they don't exist, could that be extended to the Schema that gets specified?

BrentOzar avatar Jun 11 '16 12:06 BrentOzar

Creating schema is annoying because it wants to be the only statement ij

BlitzErik avatar Jun 11 '16 12:06 BlitzErik

Overly sensitive phone screen ftl. Creating schema is annoying because it wants to be the only statement for 100 miles. Needs to be a dynamic chunk to avoid weird errors when you check to see if it exists first.

BlitzErik avatar Jun 11 '16 12:06 BlitzErik

Erik,

Yeah it's a pain.... I'm still tweaking it to be more dynamic in my code for my job, but I figured if I ran into this, others might too.

Is it a fair assumption to say that if someone is using @Output params they're probably putting it in a job? One thing I noticed was that I didn't get a create table failure, I got an error that a table didn't exist for inserts. Would it make sense as a stop gap measure to just validate at the top of the sproc if database and schema exist and then if they don't, raiserror('lorem ipsum', 20,-1) with log? I figure that people don't always check for job failures but they may check error logs...

This kind of brings up another question. At this point in time if I specify a database that doesn't exist, I don't get any failures at all. I have no way besides actually checking my work to find out that this didn't actually do what I expected. Probably out of the question to create the db, but would the raiserror be a good fit here?

AndySchwabe avatar Jun 11 '16 15:06 AndySchwabe

Oh yeah, we're totally not against doing it - Erik was just chiming in on why this will be a little tough. (He closed it accidentally when doing a comment on his phone.)

After looking at it for a few minutes, I think we'd just do a raiserror, and include the T-SQL to create the schema as part of the error if the schema doesn't exist. (If the database doesn't exist, I wouldn't wanna try to guess the T-SQL on that one since drives/files/etc., but creating the schema would be easy enough.)

BrentOzar avatar Jun 11 '16 15:06 BrentOzar

Just build the db in C:\Windows\system32. It's where the good databases live! I do like that the sproc still runs to completion if the output table doesn't exist. Just want it to give a little bit more verbose output. If I wanted to work on this myself, just branch, commit, test, pull request when done? Or are you guys not quite ready for that yet? Part of me feels a bit bad just submitting small feature requests that I could really easily work on myself...

AndySchwabe avatar Jun 11 '16 15:06 AndySchwabe

Yeah, you can totally branch/commit/test/pull. Next week, the code's probably going to be changing fast and furious while we switch in the MIT licensing, standardize on comment blocks, etc, but the merge on that shouldn't be too bad. Thanks sir!

BrentOzar avatar Jun 11 '16 15:06 BrentOzar

Been a while since anyone touched this. Going to close. If you want to work on it again, open a new issue.

Thanks!

BlitzErik avatar Jan 27 '17 14:01 BlitzErik