10,000 foot overview question on SQL Server query composition - sql-server

I've just migrated from Access where I would "write" SQL constantly and quickly using their GUI layout. I'm very new to SQL Server and am puzzled why is there no query GUI in SQL Server. Is it just that much more powerful that a GUI wouldn't be able to address the majority of queries? Or is it like a purist thing where once one is no longer in watered down databases like Access that he or she should just know SQL well enough to write it on the fly. Or am wrong altogether, and there IS a graphical way that most programmers compose SQL?
Sorry for the umbrella question, but I think some theory here would help me understand the big picture better.

I think there is a Query Designer as part of Sql Server Management Studio: see for example SQL Server 2005 Management Studio Query Designer.

The SQL Server is a database server. That it self does not have any editor text or GUI. You can mange it from the console, or any dedicated software that might have or not a query designer.
The main difference between Access and SQL Server or any other database, is that the MS Access is application that store the data in a file, when You close "Access" anything can happen inside the database by it self, while you are using SQL Server it is alway on You only connect to it. That why access have build nice query, report form designers. The SQL Server has totally different job to do and does not need this. With SQL Server we have Sql Server Management Studio, whit serve to global management not only for table creation and query design, there is a lot of background staff going on right there for example user management, rights jobs.
So it is not that SQL Server does not have a query designer, You just don't use proper software to work with it. A power full application is SSMS that ChrisW presented.

Actually there is a GUI-Designer for Views and Queries. Just use the SQL Server Management Studio.
For Example on the "Views" right-click and choose "Add View...". The view GUI is looking very similar to the one in access.

AFAIK about MySQL. Earlier there was the MySQL suite of tools and now there is the MySQL Workbench.
Say what you may, but it's definitely a timesaver.

First off, I believe the query designer in SQL Server Management Studio is probably the equivalent of what you've used in Access. I'm not terribly well-versed in using Access except through code, but I think you can do what you want there (in query designer). I've never found it to be very flexible, so I always end up back in the code itself, but there you go.
My other answer is a little bit off topic (and posted at this point mostly for googlers), but if you're a developer (especially using SQL Server), it probably still applies: Linq to SQL in Visual Studio.
I've been developing against SQL Server databases for about 7 years now, and most of that time has been spent writing the SQL statements out by hand. Last year, I changed jobs and finally had an environment where the databases my programs used were local and didn't change structure. I finally had a good opportunity to begin using Linq!
Linq is an amazingly useful tool!!! I now use it for almost (not quite) all of my database interactions from code.
The basic gist is that you create a graphical database layout in a dbml file. This layout includes tables (or views) as objects and association (PK/FK relationships) as links between the objects. How you set up the associations determines whether that property is a single object or an entity set of that object. Imagine you've got the following:
TABLE (ORDERS) TABLE (CUSTOMERS)
-------------- ----------------
PrimKey
CustomerID --(FK)--> PrimKey
OrderDate CompanyName
Using Linq to SQL, when you run something like the following:
Using db as new DataBaseContext
Dim orders = (From iOrder In db.ORDERS Order By iOrder.Customer.CompanyName).ToList
End Using
You end up with a list of Order objects that each own its corresponding Customer object. You can set this up to have object hierarchies and it pretty much works like you'd expect.
Anyway, it's a fairly big topic and more to get into than is appropriate here, but suffice to say that I think it's a great technology to bridge graphical interaction with true, nitty-gritty code.

Related

Automated SQL Server slow query report?

I am a developer and performance tester but not a DBA. My team is working on a performance testing tool that is specific to our software. One of the features we want it to have is the ability to generate a database report immediately after the test. Our software is database agnostic. For Oracle, I can easily create a snapshot id before and after the test and programmatically create an AWR report for those snapshots, write to a file and save with other artifacts we gather. Works great.
For SQL Server, however, there is no AWR equivalent (that I know of). I know the MDW as part of the SSMS has a UI for getting things like top 10 slow SQL and things like that. But, I have not yet found a way to programmatically create and extract a SQL performance report (preferably similar to Oracle's AWR) for SQL Server.
I am even willing to create the report myself if I can find a way to extract the raw data.
Any ideas would be greatly appreciated because searching online is not getting me anywhere.
P.S. I'm trying to do this in Java, by the way, but will accept help in any language. Thanks again!
Good news! In SQL Server 2016, you can use Query Store. This is like your flight recorder blackbox.. finding long running queries and waits. Capture baseline built in to SQL Server. You can compare before and after hardware changes and/or upgrades on queries. Maybe this similar to Oracle AWR.
Only available SQL Server 2016 and up.

Can't make changes to SQL backend from an MS Access Data Project

I have a MS Access 2010 Data Project (adp) connected to MS SQL Server 2008. Based on Microsoft's website, I should be able to modify the SQL backend from within the MS Access 2010 Data Project.
Once you connect to an SQL Server database, you can view, create, modify, and delete tables, views, stored procedures, user-defined functions, and database diagrams by using the Database Designer, Table Designer, Query Designer, Query Builder, and SQL Text Editor.
However, I can't modify all my columns the way I want to. Let's say I have a table with
Col1 varchar(255)
I can't change that in Design View to varchar(max). Max is not an accepted length in MS Access. Also, per Microsoft's documentation, text should not be used, since it's deprecated. So, I would like to avoid that as a solution.
Another option would be to make the change directly on SQL Server. However, this won't work for me. There will be other developers working on this. None of the other developers will have access to SSMS. Mostly because they're Access developers, who have never seen SSMS or even touched SQL Server before.
How can I make this change in MS Access Data Project? Are there any other gotchas that I should be aware of with this client/server model?
There are a few field type comparability issues that you have to work around when using access to design tables and other SQL Server objects. Generally I've found Access to be a very useful front end client for data entry forms, programs, and reports on SQL Server data. However, I always use SSMS for creating tables, procedures, views... and all SQL Server related development tasks.
As for your table design issue, it looks like most activities are supported except for a few data type issues. One option could be to have your developers send ad-hoc T-SQL statements to the server to create and alter tables that have unsupported field requirements. One way to do this would be to create an access form with a text box to enter the T-SQL statement and then a click of a button calls some VBA to execute on the server with CurrentProject.Connection.Execute(SQLStatement). Although this wouldn't be a pretty table design GUI and the developer would have to know the T-SQL syntax to do what was required.
My recommendation is to just get your developers SSMS and some training. It's really not that much more complicated than using the Access table design interface... in fact it's very similar. They will certainly pick it up very quickly. Plus you will be leading them on a path to being informed and productive SQL Server developers.

SQL Server Building Software

What are the option in terms of applications that help build SQL statements against a SQL Server database?
We have some users that need to build SQL statements, preferably through drag and dropping or linking up tables etc.., against a SQL Server databse who don't have any experience in this area.
Any Ideas?
Visual Studio 2008 / 2010 have this featue and works well. I mean LINQ to SQL or Entity Framework, but in bigger projects I dont prefer Entity Framework.
The Sql Query editor in sql server 2005 and above is very good for that sort of operation. I found that the combination of drag and drop columns with the sql instructions below helps non-sql developers learn a little about sql and tends to wean them off of the editor.
I actually just ran into this problem in my own project.
One option is to purchase a tool that does precisely what you're looking for. If you do something like that, you're more likely to get something that's full-featured, well-supported, and has a lot of nice bells and whistles to make your job easier.
However, as both Svisstack and george9170 pointed out, there are already tools within the Visual Studio development environment. Here is how I'm proceeding:
I use Microsoft SQL Server Management Studio's Diagram editor to perform the dragging and dropping of tables. This works fairly well, although it's a bit more cumbersome to work with than some of the tools I investigated. (For the record, the reason I didn't use the tools I investigated was the cost.)
Once I develop the tables in the diagram, I tell MSSMS to generate the tables.
I then use the Database Publisher (it comes with VS2008 and VS2010) and I connect with the database. Using LINQ to SQL, I let the magic work behind the scenes so that I can utilize the various objects which will interact with the database.
If I'm not explaining this well, check out the two links below. It should make things more clear.
Using Database Projects for Visual Studio
NerdDinner - An ASP.NET MVC tutorial, but with good information on LINQ to SQL.
By using LINQ to SQL (as described in the second link), your users should be able to build queries against the database fairly easily. It's not drag and drop, but it's very simple and straightforward.
First, I hope they are not doing their queries against a production database!
For regular non developers, try using excel, for these reasons:
1) most generic users might have it on their PC already.
2) drag and link tables. There is a little GUI for simple drag and link tables in there.
3) Support. When they get into trouble, they can e-mail me the file and I can see what they have so far. I'll end up writing views or procedures for them to use.
4) They can use the results data using familiar excel interface and functions, which helps since their SQL ability is so limited.
For developers these GUI tools are extremely limited in what you can do with your queries. I've never found one that can do UNIONs, derived tables, or CTEs. I'm not sure if any can even do OUTER JOINs. For simple tasks, they might be ok, but to switch back and forth all day would be a pain, so I just type them up.
You can use Access databases as well. They let you form your own queries by dragging and dropping in Access 2010. However, if you are looking for easy to access data without the worries of SQL syntax, you might want to look at using Ruby ActionViews. If you are talking about live editing of the entire database if the database is of any importance (you can easily delete or clear an entire database on accident), I would do it in pure SQL, or better yet, not do this at all. If you are using MySQL, you should look at the possibility of using phpmyadmin for maintaining your database. It is a web based tool that makes database administration easy and can help you form your queries.

How do you generate a database schema diagram in visual studio (express)?

Right now all I did was use the Dataset designer and dragged tables into it from the Database Explorer. It works (for what I need anyway) but it feels like it's a misuse of Datasets. (Actually I'm not really sure how to use Datasets or what the intended usage is, I was planning on using LINQ2SQL to interact with the DB)
Is this ok? I only need it for the designer view and it's a very simple DB layout (just 4 tables). I'm sure there's other tools out there, but is there anything integrated into VS Express that I should be using instead?
You download MS SQL Express with the SQL Studio Management Studio Express. Only in the Studio Express can you connect to the server, select the database, open the database diagrams and edit diagrams.
Then, you can drag and drop the entire set of Tables in to Linq to SQL. Entity Framework is nice, but I have yet to get it to render my tables well yet. I would stick to Linq to SQL until they release another upgrade to EF (easier for you).
You say it works, and you want just want to make a diagram, so go with it. You should make sure it doesn't build the generated code file, however, as it could cause bloat in your final product.
If you're not going to use it for code and it provides adequate output for you, what does it matter if it's a "misuse"? I know people who used Excel to design documents because it was easier to line things up that way. I would use Word, and it's clearly not Excel's stated main purpose, but does it mean using Excel was wrong?

Simplifying SQL Server's Logins/Owners/Schemas/Roles/Principals etc

I frequently develop small internet applications using ASP.NET and SQL Server 2005. My databases are always only accessed by one application through an ASP.NET web service or something similar.
When I'm developing an application and moving a database back and forth between my development computer (SQLExpress 2008) and hosted server (SQL Server 2005) invariably I end up getting a hodgepodge of owners/roles/schemas/logins etc that seem to crop up and take control of various pieces of the database.
I only know enough about SQL Server to be dangerous, and I just want to get databases designed, but I invariably have to change the db and end up getting various permissions errors (for example when trying to open a diagram after transferring a db).
Is there a way to simply tell SQL Server Management Studio "Hey, I'm the only guy who's going to use this stupid db, so just let me do it?"
Like some command that sets all of these pieces to 'dbo' or something like that?
I am assuming you are using Windows. Make sure you are connecting to SQL with Windows authentication and give your account Sysadmin permissions. Now everything you create (Create Table tablename, Create View viewname) will automatically have dbo as the owner.
Unfortunatly there is a couple of easy answers to your question, but you are probably not going to like them because they will require you to invest in SQL Server skills.
The first tool you should look at is Visual Studio 2008 Database Developer Edition. This version has management tools you are looking for to manage schemas, users, ... I thinks this is now included with Visual Studio 2008 Development Edition
The second approach is to embrace SQL Server administration and get comfertable with writting DDL scripts. The goal is to get to the point where you can deploy changes to SQL Server in a predicatble manner from your development enviornment to test and ultimatly to production.
The crux of the problem is that you move back and forth the database itself. Databases are surprisingly tightly coupled to their host SQL instance, by the login to user mapping and by other settings as well, like encryption keys, usage of msdb procedures and maintenance plans among other. You could minimize some of the impact by carefully using exlclusively SQL Authentication, but that won't eliminate the problem completely. The real solution is that you should have a deployment script and apply changes to your production database(s) via executing T-SQL script(s) that you have previously tested on your development db, not by moving a db 'back and forth'.
I create all objects specifically specifying I want them created as dbo.
so to create a proc I do
Create Procedure dbo.myprocname

Resources