I am looking for a way for SQL Server Management studio to show me the last SQL query that was run. For example, when I make modifications to a table in the designer mode, I will eventually want to make the same changes to the production DB without recreating the entire table. I'm looking for functionality similar to PHPMyAdmin for MySQL which tells you the last query ran and the results of the query at the top of the page after the modifications are complete.
SQL Server – How to Show Last Executed Query in SQL Server Management Studio
sql server
Related Solutions
I can't speak for anybody else, but I usually just type SQL in "freehand", as you put it. Most of the visual query designers seem (to me) to increase complexity rather than reducing it. I should add that I don't write SQL anywhere close to full-time either.
Advantages of SQL Server over MySQL:
- Transactions. MySQL doesn't fully support transactions (any operation on MyISAM tables, as well as any DDL statements, will silently commit a pending transaction, which makes the transaction support practically useless)
- SQL Server, Visual Studio, and the entire .NET ecosystem, are built to work together. While you can use MySQL with .NET, it doesn't integrate as nicely.
- More powerful stored procedures. T-SQL has a complete set of imperative programming features, and while the syntax is still far behind a proper programming language, you can do amazing things with it.
- You can import .NET DDLs into SQL Server and run .NET CLI functions from within T-SQL queries: this means any function you feel is missing from your SQL dialect can be provided through this mechanism (I used this once to order query results by geographic distance)
- SQL Server has better replication support. If you ever need to scale your database beyond a single-server or simple master-slave configuration, MySQL will be trouble
- Finer-grained locking. MySQL often locks entire tables; the result can be that if you run an expensive query joining two or three of your most important tables, these tables may be completely inaccessible for several seconds. SQL Server has more sophisticated per-row locking, which means even though you're querying some rows in a table, other rows can still be inserted or modified concurrently.
- Native support for GUIDs as primary keys - if you prefer GUIDs for your keys, that is (which is one way to reduce migration pain).
Downsides:
- Cost. MySQL is essentially free; SQL Server licenses come with a hefty price tag (unless you can use the Express version - but be prepared to pay once you hit the size limit)
- Scriptability. MySQL is built with a command-line mindset, and it is very scriptable; SQL Server, coming from Microsoft, wants you to use the full-blown GUI for pretty much everything, including backup scheduling, migration, maintenance, etc.
- Platform lock-in. MySQL runs on practically everything; SQL Server requires Windows.
Perceived advantages that don't actually hold:
- Performance. Yes, MyISAM is faster than SQL Server, but it's also dangerous and incorrect. MyISAM doesn't support transactions, and it can't enforce foreign key constraints (due to its one-file-per-table approach). As a result, it is easy for a bug in your code (or simply a network outage) to corrupt your database. Most MySQL-based applications I have worked with include code that 'fixes' the database at regular intervals, trying to clean up the mess left behind by rogue queries and other glitches. Also, as soon as concurrency is involved, MyISAM's full table locking behavior easily devastates all performance you might have won.
That said, there are other alternatives - postgresql, which gives you many of the advantages of SQL Server, without the price tag and the vendor lock-in, is my personal favorite.
Best Answer
If you want to know what is the query corresponding to the change you've done to a table (or other object) in designer mode, use Generate Change Script (Table Designer → Generate Change Script... or the very first icon, with a diskette and a script, in Table Designer toolbar) command.
Note that actually you don't need to commit the changes, which makes it a good medium to learn things. For example, if you've forgotten how to create a primary key which spans on multiple columns, one way is to Google it; another one is to create such key and see the change script.
If you rather want to track all the queries, not just the ones made by the designer, use the profiler (Tools → Sql Server Profiler).