sql-server

Sync SQL Logins utility on 2005/2008

Anyone point my at a utility for syncing sql server logins after restoring a database to a different server? I know I can do it with scripts, but I've been using a wonderful little utility - 'Db Maint Sync SQL Logins' (http://www.dbmaint.com/SyncSqlLogins.asp) to do it on sql server 2000 which unfortunately doesn't support 2005 and I'...

Data length in ntext column?

How do you find out the length/size of the data in an ntext column in SQL? - It's longer than 8000 bytes so I can't cast it to a varchar. Thanks. ...

SQL Server: Make all UPPER case to Proper Case/Title Case

I have a table that was imported as all UPPER CASE and I would like to turn it into Proper Case. What script have any of you used to complete this? Thank you. ...

Is there a clean T-SQL query I can use to verify an index has the right columns?

I am writing a DB upgrade script that will check to see if an index has the right two columns defined. If it doesn't, or if it only has one of them, then I will DROP it (is there a way to ALTER an index?) and then recreate it with both. ...

Database-wide equivalent of SET IDENTITY_INSERT OFF

In my eternal saga to insert 1.4 million rows of data from a SQL script, I've written a basic WinForms app that takes each line of the script and executes it individually. However, because the original script contained SET IDENTITY_INSERT [Table] OFF and SET is a session-wide command, this setting is getting lost on every SQL call, m...

Calling a Stored Proc from within a Stored Proc and returning a recordset.

I have a Stored Procedure that rolls-back a series of operations. I want to call this from within another SP. The problem is that the inner SP returns a record set with a single value that indicates the degree of success. This approach worked well and has some advantages in our context, but in retrospect, I would have done it the con...

CREATE TRIGGER is taking more than 30 minutes on SQL Server 2005

On our live/production database I'm trying to add a trigger to a table, but have been unsuccessful. I have tried a few times, but it has taken more than 30 minutes for the create trigger statement to complete and I've cancelled it. The table is one that gets read/written to often by a couple different processes. I have disabled the ...

Insert default value when parameter is null

I have a table that has a column with a default value: create table t ( value varchar(50) default ('something') ) I'm using a stored procedure to insert values into this table: create procedure t_insert ( @value varchar(50) = null ) as insert into t (value) values (@value) The question is, how do I get it to use the defaul...

How do I ensure a column contains one of a set of values?

I'm creating a table that looks something like this. CREATE TABLE packages ( productCode char(2) , name nvarchar(100) , ... ) I want to make sure the productCode is always one of two values: XJ or XD. How do I do that? ...

How to persist a calculated GEOMETRY or GEOGRAPHY column

I'm trying to create a table under SQL Server 2008 containing a GEOMETRY column and a calculated variation thereof. Considering the following table where the calculated column returns a buffered geometry: CREATE TABLE [dbo].[Test] ( [Geometry] GEOMETRY NOT NULL, [Buffer] FLOAT NOT NULL, [BufferedGeometry] AS ([Geometry]....

Should I index a bit field in SQL Server?

I remember reading at one point that indexing a field with low cardinality (a low number of distinct values) is not really worth doing. I admit I don't know enough about how indexes work to understand why that is. So what if I have a table with 100 million rows in it, and I am selecting records where a bit field is 1? And let's say tha...

Is there a solution for deploying IIS websites that's similar to Capistrano?

Capistrano is a great solution for building scripts that automatically deploy a website and/or a database. But, it's also very *nix centric, and from I've read it would probably be more trouble than it's worth to get it working with a Windows server. Is there a similar solution that would allow me to deploy an ASP.Net website to an IIS s...

Stored Procedures - End of days.

I’m listening to the Hanselminutes Podcast; "StackOverflow uses ASP.NET MVC - Jeff Atwood and his technical team". During the course of the Podcast they are speaking about SQL server and say something along the lines of 'The days of the Stored Procedure are over'. Now I'm not a DBA but this has taken me a bit by surprise. I always assu...

Text overflow when using nvarchar(max)?

I've run into a strange situation that seems to involve long text overflowing. I'm using fn_pcre_replace (from the xp_pcre extended stored procedure) on an nvarchar(max) column, and when I replace with more characters than were there originally, it returns NULL if the original string was over 8000 characters long. For example, this Se...

How long should SET READ_COMMITTED_SNAPSHOT ON take?

How long should it take to run ALTER Database [mysite] SET READ_COMMITTED_SNAPSHOT ON I just ran it and its takin 10 minutes. How can I check if it is applied? ...

In SQL, how can you "group by" in ranges?

Suppose I have a table with a numeric column (lets call it "score"). I'd like to generate a table of counts, that shows how many times scores appeared in each range. For example: score range | number of occurrences ------------------------------------- 0-9 | 11 10-19 | 14 20-29 | 3 ......

How do I check if a column exists in SQL Server?

How do I check if a column exists in SQL Server 2000? ...

Way to preview (retroview) SQL queries of SQL Server Management Studio Express

Could you tell me, please, if it's possible to preview (or at least retroview, for example, in a kind of a log file) SQL commands which SQL Server Management Studio Express is about to execute (or has just executed)? In the past I used Embarcadero DBArtisan which shows SQL queries to be executed before actually running them on the serve...

Exporting reports - Quest's Spotlight on SQL Server

I'm setting up some monitoring on a few SQL Servers. Currently our environment uses Hobbit Monitoring System, but we are probably migrating to Nagios pretty soon. One of the DBAs recommended Spotlight to me, and it seems like a great piece of software, but here's what I'm wondering... Is it possible to configure Spotlight to report som...

Are there conflicts between SQL Server 2005 and SQL Server 2008?

I am told that SQL Server 2005 installation with BI tools and SQL Server 2008 with BI tools can't work together on the same computer. Apparently "some" things stop working. This was told to me by one of my team members. Since I'm new to SQL BI, I cant discount what he has said altogether and I dont want to install them both on my dev box...