Microsoft SQL Server in Sublime Text 2? - sql

I am a sublime text lover but at my job I am forced to use Microsoft Visual Studio along with Microsoft SQL Server. I want to possibly just use sublime since I'm quite familiar with it and my workflow is just so much better. To do so I would need to know how to run the SQL queries in sublime text? I have been doing some research and found a couple builds but none that work so I'm wondering if it's even possible if so how?

It's difficult to create complex IDE from ST2 due it's ascetic UI API.
Even OracleSQL package doesn't give the power of PL/SQL Developer or Toad for Oracle.
So, maybe it's better to join SQLMS with ST. For example write in ST, but run, debug and edit in SQLMS.
Here is my setup for using ST and SQLMS together.
Set up ST to auto re-read file changes if file saved
Set up SQLMS to auto re-read file changes if file saved
Set up External Tool - "Open in Sublime Text" in SQLMS and bind it to ctrl+o,ctrl+s
command: C:\Portable\Sublime Text 2\sublime_text.exe
args: $(ItemPath):$(CurLine):$(CurCol)
dir: $(ItemDir)
Install improved "SQL Ex.tmLanguage" syntax highlight from here
After setup you can open same file in ST and SQLMS and switch between editors easily.

Late to this but was just trying to do the same thing.
A very crude solution I just tested in ST3 uses the following (you need to create a new Build system in ST and then associate it with your SQL file)
{
"cmd": ["sqlcmd", "-E", "-i", "$file"]
}
It uses a trusted connection to SQL and assumes the sql script will either run as-is in the default database, contains a "USE" statement or table names are otherwise fully qualified.
For additional tweaking, run sqlcmd /? from a command prompt or read more here

TSQL Easy is a package you can download which has some tools to run TSQL and SQL scripts. It also has good TSQL syntax highlighting in sublime text 2. Actually it's the only TSQL syntax highlighting I've found so far.
You can get the package here (or through package control): https://github.com/tosher/TSQLEasy

Related

SQL table view (Visual Studio or...)

Is there any way to read .SQL document in table view in VisualStudio or any other program?
.sql quite simply contains a set of executable SQL instructions. ( described here ) The instructions are in plain-text and are can be viewed with any text editor (i.e. notepad).
Based on the way your question is phrased, I assume you have instructions to create a table in SQL which you would like to view in a more user-friendly way. The best way I can think of to do this (although I am not extensively familiar with Visual Studio), is to set up a test sql environment (on localhost/a testing server - XAMPP comes to mind). Then open up phpmyadmin (or another database manager, although phpmyadmin is packaged with xampp) and run your code... and, if teh code is not your own, obviously look for sql injections ;) .

How to run multiple .sql files in Eclipse DTP

I've a list of .sql script files to create Stored Procedures which I'm using the Eclipse DTP to develop. Currently to create/update all these Stored Procedures, I've to open & run
one by one from the Data Perspective.
Is there a way to create a batch file that run the scripts along the lines of
run createSP1.sql
run createSP2.sql
...
run createSPn.sql
and run it in the Eclipse DTP to avail of the DB connection defined there?
why not just create a batch file that merges all of your .sql files together into a single procs.sql file as part of the build process. I don't know what platform you're running on but in Windows you could have a .bat file that does something like this:
type *.sql > proc.sql
then to apply it to the database, why not do it outside Eclipse and connect to the database via the command line. You could bundle this all up as a single batch file that gets the latest version of your stored procedures from source control, merges them into a single file and then applies it to the database.
Part I
As far as I know the developers of Eclipse DTP
have not yet implemented a command line SQL execution
interface through the Eclipse console view.
See the following URL on the eclipse DTP developer forum
http://dev.eclipse.org/newslists/news.eclipse.dtp/msg00304.html
Part II
While the Eclipse DTP people are working on it,
you can use a database specific tool to load
a master SQL file (all SQL proc files
appended together)
There are database specific console
tools that will load your master SQL file
command line.
(ie. SQL*Plus for Oracle, ij for Apache Derby)
Part III
An improvement over DOS batch is using Cygwin bash
or python or perl to merge all of your sql files
together into a master file.
I found that the text processing tools available
in UNIX (awk,sed,cat...) are great for this sort
of thing.

DB Pro (data dude) and Wix3 SqlExtension

I'm attempting to use Wix to create a database during install. I have my database setup with the Db Pro Visual Studio SKU (Data Dude as it's sometimes referred). However, the output seems to be only consumable by sqlcmd.exe since it uses specific syntax in it (variable references like :setenv and $(FOO)).
I'm trying to use the wix sqlextension which apparently isn't using sqlcmd.exe (I haven't investigated what data access technology it's using just yet.
Does anyone know if there is a way to use the output of data dude natively in the wix sqlextension or alternately if there is something that will take the sqlcmd output and translate it into the runtime sql needed to execute against the sql server?
Please note that the ultimate goal is to fully integrate wix into our build system so I am looking for an automated approach.
If you have created the package using Visual Studio DBPro it is best to use VSDBCMD.exe for the DB deployment. The benefits of this is that the VSDBCMD.exe always figures out the differential of the destination to the source and creates a delta script which can be run from the same command line. You just need to provide /action:Deploy.
There is a blog post that covers calling the sqlcmd.exe utility from WiX 3 at http://neilsleightholm.blogspot.com/2008/08/executing-sqlcmd-from-wix.html

How do I edit a text field (or ntext) in SQL Server 2000 or 2005 using the GUI?

Is there a way to do this with SQL Server tools?
If not, is there a 3rd party tool that does this?
There doesn't seem to be a good way to edit longer text columns in the SQL Server Managers for SQL Server 2000 or 2005. While SQL Server Manager is really not for editing data in your db, what other tool does Microsoft provide that would normally allow you to do this? Every other field is pretty easy to edit, except long text fields. In Access, you could hit shift-f2 and it would pop up a nice dialog to edit your text in.
alt text http://techinterview.org/edit.png
Generally, SQL Management Studio is an administrative tool for your database and not meant for data entry other than a quick edit here or there. Generally you would script the data or it would be entered by an application that uses the database for persistence.
(Although I have pointed Access to my SQL Server DB for a better quick and dirty UI.)
This may fight your bill - SQL LOB Editor.
The other option you might want to look at is EMS SQL Studio for SQL Server.
Marc
If you are specifically after a nice big multi-line edit dialogs, then yes you definitely need to look outside of the Microsoft SSMS line of tools. They don't support it.
This is just stupid. Enterprise Manager for SQL Server 2000 handled multiline text just fine. Just silly to go backward and loose functionality that was pre-existing. Not like it is rocket science to reproduce formatted text. Someone really dropped the ball on this one.
In the Management Console, isn't it possible to do an "Open Table" context-menu action and then edit the data from there?
I totally recommend DBVisualizer. The nice thing about it is, it supports a long list of databases and generic all JDBC Drivers (since it is written in Java). You can browse your various databases, change data and explore schema in nice graphs. It comes as a free and a personal edition for 149 $ and is totally worth it! Look at this matrix for a comparison.
You'll be able to edit text and ntext in SQL Server 2000, 2005 and surly for upcoming versions as well.
If I had to make the edits only occasionally I would probably use SQL Query Analyzer and just script the UPDATE command.
If that was too inconvenient I would next look at linking to the database in Access, and to really quick and dirty ease of use I would just use an AutoForm to generate a UI for the table. If you don't have Access I believe OpenOffice Base can connect through ODBC and has similar form building functionality.

Editing SQL query with Visual Studio 2008

Would you recommend me the best approach to edit SQL query with Visual Studio 2008 Professional, please?
I know I can open Query window from context menu in Server Explorer and edit text in SQL Pane. But unfortunately I am not allowed to save query to a file and Find and Replace commands are not working there.
Alternatively I can open text file with extension .SQL in Visual Studio editor obtaining syntax highlighting and full editing capabilities but losing possibility to execute the script.
Now I copy query text from one window to another and back but I hope there is better solution.
Many thanks for suggestions!
When I have to connect to Sql Server, I use NetBeans, as it has a number of features that make it much easier to use than Visual Studio. One of these is intellisense, which is very useful when you have an alias for a table name and lots of long field names. The general handling of connections and connection pools is also much cleaner in NetBeans. I could go on, but suggest trying it for yourself. You will almost certainly need the Sql Server jdbc driver, which can be downloaded from http://msdn.microsoft.com/en-us/data/aa937724.aspx
If you create a Database project within your solution in Visual Studio, then you can set up a default database connection for that project. Then any *.sql files that are included in the database project can be executed against that connection. What I usually do is select the text to be exectued and right-click it, then select "Run Selection".
You can set up any number of database connections under the "Database References" node in the solution explorer, and choose the one you want to run your query against.
Wow you are right, this is a real pain. Would it be acceptable for you to use a local copy of the SQL Management Studio (the name might be wrong)? You would be outside of VS but you could still edit your query and run it at the same time. Definitely not optimal but better than nothing.
Good luck.