code template in management studio - sql-server

Can I find in management studio the Following feature?
I want to write a specific word and that it be replaced by a statement specifies. Ex: I write "ss" and replace "select * from" or write "johnid" and is replaced by "where id = '555 '"
 
In Toad for Oracle You might still in: "option - behsvior - template code - code template"
http://www.toadworld.com/Blogs/tabid/67/EntryId/343/Customizing-Toad-Code-Templates.aspx

There is nothing I know of built into Management Studio that will behave exactly like you are suggesting. There are some shortcuts you can advantage of in Tools > Options > Environment > Keyboard > Query Shortcuts, but these run the code rather than paste them into your window, so you can't use them as partial syntax completion. For example if you assign SELECT * FROM to Ctrl+9, then open a new query window and press Ctrl+9, you have an empty query window and the following error message:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'FROM'.
Chris already mentioned templates, so I won't treat those.
In SQL Server 2012 you can use a new feature (well, an old feature recycled from Visual Studio) called Snippets, which I think is a lot more powerful than the Template feature (I wrote about them here, and someone else did a decent job here). But I still don't think it's quite what you're after - there's a menu system to go through to insert a snippet, and so far in my research I've been unable to assign a keyboard shortcut -- even though there is an empty element in the Snippet XML called <Shortcut></Shortcut>, and most of the people who talk about this feature mention it, but I've yet to see a working snippet that used it (and I have tried many variations to get it work like it does in Visual Studio with no luck).
You can also use 3rd party tools, such as Mladen Prajdic's free SSMS Tools Pack. For what you want to do, I think this is the best fit, since it allows you to do real expansions snippets where the replacement text is put into your code based on the keyword you typed ad further keystrokes. However if you're using SQL Server 2012, at the time of posting we're still waiting on a compatible release for that version of SSMS. You may also want to look into Red-Gate's SQL Prompt, but I'd try Mladen's free tool first if you can. I'm sure there are other alternatives you can turn up with a standard search.

This feature is present in these free add-ins:
SSMSBoost or SSMS Tools Pack

Use Template Explorer
SQL Server provides a variety of templates. Templates are boilerplate files containing SQL scripts that help you create objects in a database. The first time the template explorer is opened, a copy of the templates are placed in the user’s folder in C:\Users, under AppData\Roaming\Microsoft\SQL Server Management Studio\110\Templates.
You can browse the available templates in Template Explorer, then open a template to incorporate the code into a code editor window. You can also create custom templates.

Related

How to get logs into the Tool Log in Release Management for Visual Studio

In the Release Management for Visual Studio Deployment log, which can be found under the Details button found when viewing the details of a release, there are a number of columns.
The last three of these are Tool Log, Command Output and Status.
I have never seen anything in Tool Log, but I am in the situation now where I have a component running tests using vstest.console.exe.
Under "Command Output", I see the output from this program as it appears in the console window. However, vstest.console.exe can also be instructed to create a test log (a .trx file), which I would like to view under Tool Log. But I have no idea how to make this happen.
How do I get a log to appear under the Tool Log column?
The answer, it seems, is to set the "Log File Name" in the Tool definition to whatever log file you wish to view (in my case, the .trx file).
This obviously requires that you are using a tool that defines this, or a custom one. Fortunately, I'm using a custom tool.
Your Tool have to copy/create the .trx file to/in the Tool's work directory (%LOCALAPPDATA%\Temp\RM\T\RM\\).
Don't forget to add .trx extesion to Administration -> Settings -> Approved File Extension List.

Visual Studio 2010: Is there a way to deploy a single database object that retains the object in normal builds?

Developers have expressed a desire to deploy a single database object from a Sql Server 2008 project, such as a stored procedure, without having to use the build/deploy or schema comparison functions.
To enable this, developers have created their database object scripts including 'if exists.. drop' checks at the top of the script and have included the grant statements for the objects in their scripts.
This results in build errors that then prevent the build/deploy or schema compare functions from operating. So then, developers mark the object as "not in build" but then the object can't be deployed at all using build/deploy or schema compare.
Has anyone found a way of quickly deploying a single database object from visual studio that does not involve schema compare or build/deploy which does not remove the object from the normal build process? Manual copy/paste is not an option but scripting/macros which effectively do the same would be viable.
SQL Server Data Tools (SSDT) now provides this functionality by way of comparison. Individual differences identified in the comparison may be deployed. We have found that during development, publishing tends to result in overlaying the simultaneous changes that other developers are making on the shared development database server. The comparison tool has been working fairly well, except for a very annoying crash issue that occurs when the comparison window is closed. We are using 32bit Vista with 3GB of RAM and VS 2010. This issue may not occur in other configurations.
First I'd like to comment that you seem to be fighting the intended paradigm with regards database projects.
If your project is deployed somewhere [1],
then there should be a corresponding branch / label [2] in your source repository.
If you change a single object [delta] from the above baseline [2], and build the new version [3],
then when you deploy [3] to [1], the deployment script should find only one difference, and the net effect of the change [delta] is all that will be applied.
So, in theory there's no reason not to just simply build and deploy.
TIP: When taking on a new paradigm, it pays to embrace it fully; partial adoption tends to cause its own set of problems.
However, that said, I may be able to help.
We have a similar need because actual deployment is out of our control. We control only part of the database, and have to provide our changes to another team for review.
We have to provide individual 'self-contained' scripts for each object with if exists..drop at the drop and grant permission at the bottom.
However, we want the other benefits of working with the database project, and then simply copy out the individual script files when we "deploy".
The solution we came up with was to place the extra "bits" in a comment block as follows:
/*SINGLE_OBJECT_DEPLOYMENT
if exists (...)
DROP ...
--*/
--/*SINGLE_OBJECT_DEPLOYMENT
if exists (...)
DROP ...
--*/
Note that a simple search and replace of /*SINGLE_OBJECT_DEPLOYMENT with --/*SINGLE_OBJECT_DEPLOYMENT enables the commented out code, so it can be easily put into a macro, or other semi-automated process.

SQL Server 2008 Intellisense - Typing 'top' brings up tables, causes confusion [duplicate]

Either the autocomplete in SQL Server Management Studio 2008 is buggy, or I am. Either way, when I try to type this and hit the spacebar:
SELECT TOP
Autocomplete immediately changes it to this (Topics is a table in one of our databases, btw):
SELECT Topics
Is there a way to fix, or at least gracefully work around this?
Unfortunately, no. SSMS Intellisense is a 1.0 product, and is not as feature-rich as many third-party products. You can turn it off OR ignore the suggestion (with the ESC key).
I think all you can do is hit ESC when the intellisense pop-up appears which will cancel any change it makes, or just turn Intellisense off completely by going to Text Editor -> Transact-SQL -> Intellisense.
I know this has been answered already but if you are looking for a tool that is quite useful/helpful try SQL Prompt from Red Gate. I have used this tool for years and found it is a great replacement for the built-in intellisense with plenty of options to allow for the tool help you be more efficient...
Also, you can cheesily add one column empty tables for the most common keywords you have issues with. Then it autocompletes to the table name but context puts it into the right usage.
Going one further you can:
CREATE table [top ] (c bit)
with the space at the end so the auto-complete is perfect.
After you create the object you'll want to hit CTRL-SHFT-R to refresh your Intellisense.

Sql Server reporting services 2008 Rendering Excel

I am trying to produce SSRS reports to integrate with a MOSS Dashboard. Reporting Services 2005 only seems to be able to render .xls out of the box. Does SSRS 2008 have the ability to render in xlsx format?
To the best of my experience, exporting to excel2007 is not built into SSRS2008, you need to get an external component for that. Currently looking into what is available on the market, i'll get back to you with what i find.
Edit:
Ok had a look at both aspose.cells and OfficeWriter by SoftArtisans. Both claim to offer .xlsx-exporting capabilities for SSRS, but in both cases this is a partial truth at best.
Both work by having you recreate your report in Excel using their respective add-ons, and then pasting their own markup into your RDL-file. This also has the effect that if you are making an excel-exportable report in either tool, you won't be able to view or export it in anything else from SSRS. Both have the ability to open an existing report and access their datasets from there, which is a major advantage over trying to get MSQuery to work for you.
Aspose suffers from various issues with permissions on the server, where you need to grant it full trust (not everyone would want that). I also had a major hassle getting it installed properly.
OfficeWriter has some issues with shared datasources, where you generally have to go in and set them manually after you've published your report. It also seems to choke on VS2008 RDLs, if you want to use a dataset from a VS2008 report, you have to make a new report in VS2005 with your dataset, and use that as a basis for your excel-built report.
Personally I don't care much for either. But overall Officewriter does seem like it comes out ahead. Next stop is figuring out if it has built-in support for matrices, or that is something we would have to program in VB to get.
According to Exporting to Microsoft Excel(msdn)
The Excel rendering extension renders a report that is compatible with Microsoft Excel 97 and later.
This seems to suggest the old format.

Oracle packages in version control?

Lucky me, I have to work with Oracle. And packages.
I have a package that a lot of different developers are touching and it's scaring me. Is it possible to put a package inside of Version Control? Is there some kind of software out there that already does this? If not, is there some kind of export procedure? Can I just grab a file off of a file system?
How are they inputting it? The way we used to work at my last job is editing a text file, and loading it with SQL*Plus. You can just put that source file under version control.
The source must be between "CREATE OR REPLACE PACKAGE MYPACKAGE AS" and "END;" followed by a single slash on a line of its own ("/"); and ditto for "PACKAGE BODY" instead of "PACKAGE".
And yes, there's a way to pull the source out of Oracle. It's in a table, line by line, look up ALL_SOURCE and USER_SOURCE. You can pull it out with a query like
SELECT TEXT FROM ALL_SOURCE
WHERE TYPE='PACKAGE BODY'
AND NAME='MYPACKAGE'
AND OWNER='MYPACKAGEOWNER'
ORDER BY LINE
(untested as I no longer have access to Oracle) and ditto for the 'PACKAGE'.
I think it's best to load it again into Oracle using SQL*Plus; make sure to set "SCAN OFF".
We have a database level trigger to capture changes to packages and save the source in a seperate table. It's not as good as version control, but at least you know when something changes and can retrieve it if a later change tramples on it.
You can download sql developer for free: http://www.oracle.com/technology/products/database/sql_developer/files/what_is_sqldev.html. It integrates with subversion and cvs.
There is also a Visual Studio plugin (http://www.oracle.com/technology/tech/windows/odpnet/index.html). I don't know whether you use Visual Studio or not?
Try http://code.google.com/p/oracle-ddl2svn/ version control for Oracle
Take also a look at this link. It's a PHP/mySQL versioning tool which works with any database type and is fairly simple to learn.

Resources