Code Alignment In SQL Server 2005 - sql-server-2005

I am using SQL Server Management Studio.
I want to know the shortcuts for easily aligning the T-SQL Queries and codes in a beautiful format for easy readability and understandability.
Please Let me know how to align the code without using any SQL Server formatting / aligning tools.
Please do give your valuable tips to align the same, right now to align the code i mean to make the code right and left aligned i m using the TAB and SPACE BAR key which becomes very difficult when the length of code is increasing.

I also find SQL Server Management Studio's lack of auto-formatting a bit frustrating, compared to the functions in Visual Studio.
Consider upgrading to the SQL Server 2008 toolset for a handful of its formatting features. One feature that stands out is that it 'remembers' where you had indented to in the previous line (not sure if this was a 2005 or 2008 feature).
Also consider some online SQL formatting tools:
SQLInform's online SQL formatter - requires Java in your browser.
SQLRefactor from Red Gate - ~$300
Instant SQL Formatter online at dpriver.com Apparently they have a SQL Management Studio plugin for $50
SQL Format at apspot.com
Online code formatting saves an incredible amount of time. If your goal is to quickly format your code, it couldn't get much easier and quicker than copy/paste.

Related

Difference of Commands between SQL Server 2005 and 2008

I have looked through many pages trying to find this information but all I get is the backbone structure and how the SQL server runs. What I would like to know is the difference of commands. Which commands can you use in 2008 but are not supported in 2005 with or without adjusting the compatibility level. I design different queries and my clients differ in their database versions. So when I create something, I would like to know if it will work before I put the time in or start actually breaking my head over why the code doesn't work on the clients computer but it does on mine. An example would be Pivot where I have to change the compatibility.
So what commands have changed? Either a link to a page or if it's not much to type out, it would be greatly appreciated.
This technet article has a list of the new commands in SQL 2008 T-SQL
There is some info here but it's not a whole lot so I am suspect that it's complete listing
http://msdn.microsoft.com/en-us/library/ms143179(v=sql.100).aspx
Version control!
Usually lower version's commands are available and work well in higher versions. But not quite the other way around. Take a look at the following post.
Advantages of SQL Server 2008 over SQL Server 2005?
For each major version Microsoft does release improvements done or changes made under product info.

SQL Intellisense in WPF Textbox

I am building an application which contains Textbox. I want the Textbox to act just like SQl Server Editor with intellisense. I need help, can i make my Textbox act like a Sql Server Query Editor WITH Intellisense.
What you want cannot be easily achieved on the fly. You have to prepare the following,
Syntax highlighting support so SQL statements can be displayed beautifully.
SQL parser, so that you can provide auto completion suggestions.
You might start from AvalonEdit which is an excellent control that help implement syntax highlighting,
http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor
https://github.com/icsharpcode/SharpDevelop/wiki/AvalonEdit
However, I think it is still your responsibility to write the SQL parser (as #Alexander suggested) and then integrate with AvalonEdit.
Phil Factor worte an excellent blog post at SimpleTalk.com on how to parse SQL using Microsoft's SQLParser with PowerShell. At the top of the post, he has included a link to Dave Ballantyne's Cleaning Up SQL Server Deployment Scripts article, which explains how to obtain SQLParser & further work with it.
While not very specific, hopefully that will at least get you off in the right direction!

Comparing two databases

I am using SQL Server 2008, can you recommend me some tool that I will be able to compare two database instances?
Also I want to be able to choose what tables and columns should participate in the comparison.
I want to add it to our automation testing.
Thanks.
Red Gate's SQL Data Compare can do what you need. It is not particularly expensive, especially if you buy it as part of a bundle (check out some of their other products - they have a lot of useful tools) and you get a free trial so you can see if it works for your situation before you buy it.
I have used it and it works well. It allows both comparison and snychronization of data between two databases, even if the schemas are slightly different.
For the feature "Command line automation for continuous integration" you will need the Pro edition.
If you're using Visual Studio 2010 for coding along with SQL Server 2008, you can use the Schema Compare and Data Compare tools that comes along with Visual Studio 2010.
Here are some resources:
Schema Compare
Data Compare

SQL Prompt alternatives for SQL Server 2005?

I'm trying to wean myself from SQL Prompt from Redgate because I'm now on a low low budget and I can't afford to go from 4 to 5. I haven't found anything nearly as good for SQL Server 2005.
Should I just save up, or has someone found a better tool or a way to exist without the intellisense features??
You can try out free SSMS and VS add-in, ApexSQL Complete
ApexSQL Complete provides snippets and syntax checking and a lot of code auto-complete features (context based predicting keywords, users, objects, autocompleting aliases, the Insert procedure parameters automatically option , the Insert full INSERT statement option and so on)
For code refactoring you could use ApexSQL Refactor, also a free add-in
Disclaimer: I work for ApexSQL as a Support Engineer
DevArt has a similar tool called SQL Complete which seems to support SQL Server 2005, and even offers a free Express edition.
Database.NET is basic, but pretty decent:
http://fishcodelib.com/Database.htm
Free for personal use, $19 commercial license, and works with SQL Server, Access (what I use it for, when I'm forced to deal with Access databases), and a number of others.

What are some good, reasonably-priced SQL Server client tools offering Intellisense for SQL?

SSMS 2008 doesn't have SQL Intellisense when connected to SQL Server 2005! I know of 3 products which enable writing SQL with Intellisense. ApexSQL Edit, Red Gate's SQL Prompt Pro & SQL Assistant. However I am looking for a less expensive solution.
Any ideas?
Embrace Linq and use LinqPad.
Full intellisense using linq on sql servers, fully integrated with c# statements or expressions, for $27.
Those are pretty much the three choices.
If you don't want to pay for an add-in, you could always roll your own (although in the long run it may be cheaper to just pay for an existing solution). Jon Sayce has a good blog post on Building a SSMS Add-In if you want to give it a shot.
My Recommendation: Atlantis SQL Enywhere which is completely free. It works with SQL Server 2005 and 2008. I have been using it for a month now and I am really impressed with its features. Keyboard shortcuts are similar to VS, so makes the transition is really smooth to a new editor.
Some of the features that are worth mentioning.
Intellisense that actually works when using multiple tables and joins with aliases
Suggestion of joins when using multiple tables (reduces time on typing, really neat)
Rich formatting of sql code.
Better representation of SQL plans
Highlights variables declarations while they are used.
Table definition on mouse hover.
Productivity++.
Well, there is a freeware tool that works with SQL Server 2000, 2005 and 2008. Recently we have released dbForge SQL Complete, a free SQL autocomplete add-in for Microsoft SQL Server Management Studio (SSMS).
By the way, on Friday (21 January 2011), we have released a new version of SQL Complete that offers a bunch of new features. All new features are available in shareware Standard Edition (30-days free trial, $49.95).
You also can get all basic functionality, similar to v. 1.0, with Express Edition.