Tag: SQL

Exec sp_help on a table with a schema

Really quick post regarding sp_help and tables in Schemas (not in dbo). Usually when doing a sp_help, you can do something resembling the following : However, if you try to do the same with a table with a Schema (SomeSchema.TableName) you will get an error “Incorrect syntax near ‘.’”. To execute the sp_help on a table with a schema, simply...

What’s the Difference Between Where and Having in SQL?

A really quick post for you all today over the differences between Where and Having in SQL. This has been a question in a lot of interviews, but no one seems to know why and when to use each of these clauses. Where The where clause is used to filter based on criteria other than aggregates. So say for example...

SqlDataAdapter Will Not Always Return a Result, SSMS Will

The Issue I ran into a strange issue with an ASP.NET site (MVC2 – 4.0 Framework) where when executing a stored proc, SqlDataAdapter.Fill(DataTable) will not return any rows some of the time, but SQL Server Management Studio will almost immediately return results. The full method calling the stored procedure is below : (Auto-generated from LLBL Pro V2.6) This issue occurs...

View The Last 50 Queries Ran on SQL Server

I ran into an issue where I needed to see the last few queries ran on SQL Server (Currently using SQL Server 2005). There were quite a few suggestions out there, but one I found on Stack Overflow seemed to be formated the best and didn’t require me messing with the query. (See Query Below) This however wasn’t working for...

Nested Case Statements in SQL

Need to do nested Case statements in SQL? Use the following syntax. This should result in ‘a1b1 – yar’ This took me a little time to work out the syntax, but pretty simple once I understood case statements a little better. For some more info on case statements, you can go to the msdn  article located at http://msdn.microsoft.com/en-us/library/ms181765.aspx

Automated Backups of Your SQL Database

Ever find yourself taking precious time and backing up all your databases, only to forget and be behind? I am currently working on some Alpha-PreAlpha software whose database structure changes with time like any other application. To solve the issue with remembering to back up however, I decided to automate it, and not have to worry. There probably is a...

How to Add, Modify, Rename, and Delete a Column in SQL

There has been a few times where I needed to compose a script to update a customer’s database, and I’ve had to use probably the most popular of the SQL ALTER TABLE syntax: Add, Modify, Rename, and Drop. To help save for my own notes and to possibly give some help,  I thought I’d write a quick article on these 4...

Specify Your Own Select And Edit Top(n) in SQL Server Management Studio

When right clicking a table in SQL Server Management Studio, you have an array of options. Probably the two that I use most however is the “Select Top 1000 Rows” and the “Edit Top 200 Rows”. However, sometimes you want to look at a little more than that. I know most of the time I want to select all from...

%d bloggers like this: