sql-server

How does the constraints GUI work in SQL Server Management Studio?

In my TSQL table I added a constraint with the following sQL statement alter table disabledqualities add constraint uc_uIdQualCode unique (userId, qualitycode) I did it by hand because I just can't work out how the GUI is supposed to work. You add a constraint and then you get a window where you should "define" your constraint. It's b...

Why does my unique constraint show up under indexes rather then under contsraints?

I created a constraint on my tsql table like this: alter table disabledqualities add constraint uc_uIdQualCode unique (userId, qualitycode) In MSSMStudio the constraint shows up under indexes rather then under constraints. Why? --EDIT-- I understand that it creates an index to enforce the constraint, but then why is there a node cal...

Backup DB task in SQL 2005 Maintenance Plan

I have a Backup DB task setup to do a full backup of All User Databases. However, I find that when new databases are added, they do not get automatically included in the backup plan. I am forced to open the plan each time a new database is added and select All User Databases Radio button and save the package for the new DB to be added t...

How to get the maximum row for each group of key values in a single table?

I have an MSSQL 2000 table that has a lot of duplicate entries. Each row has an EffectiveChange data column. I want to get the most up to date row by getting the row with the max(EffectiveChange) for each key value. This is some sample data: NPANXX TZONE EFFCHANGE RATE 555555 1 01/01/09 1 555555 1 05/01/09 6 214555 2 0...

Generate resource free/busy query using SQL Server

In SQL Server 2005 I have a table with the following columns: Table Reservations: ID arrival datetime departure datetime reservation_object (FK to objects table) Now I need to generate a report that shows for a specified period the status of an object. This report will have to look like this: 6/1/09 6/2/09 6/3/09 6/4/0...

How to INSERT using an inverse JOIN on multiple keys?

How do I do an inverse join with more than one key column? In this baby-toy SqlServer example, I have the following CREATE TABLE [dbo].[CarList]( [myID] [int] IDENTITY(1,1) NOT NULL, [CarColour] [varchar](32) NOT NULL, [CarName] [varchar](128) NOT NULL, [CarCompany] [varchar](32) NOT NULL, CONSTRAINT [PK_CarList] PRIMARY KEY CLUS...

SQL Server slow down after duplicating database

I recently moved a bunch of tables from an existing database into a new database due to the database getting rather large. After doing so I noticed a dramatic decrease in performance of my queries when running against the new database. The process I took to recreate the new database is this: Generate Table CREATE scripts using sql ser...

SQL Server: Avoiding GUID regeneration on restore?

I have a table in which the primary key is a GUID with a default of NewID. If the PK column had a value of XYZ when I backed it up, I would expect XYZ in the restored table. In fact I get PQR (well the GUID equivalent). It looks like the GUID gets regenerated on restore. Is this in fact happening (it seems a little crazy), and if so, how...

Database VIEW does not reflect the data in the underying TABLE

Input: The customer claims that the application (.NET) when querying for some data returns data different from when the customer looks into the data table directly. I understand there could be various reasons and in completely different places. My purpose is not to solve it here, but rather to ask experienced DBAs and DB developers if:...

How to type a new line character in SQL Server Management Studio

In the "datagrid" view of an open table of data, how can I type a new line character into an nvarchar field directly in SSMS? Is there an alt code? ...

Since there is no Sqlserver array parameter, what's the best way to proceed?

I need to create multiple records in sqlserver, each with the same value in column A, but with a unique value in column B. I have the values for column B in an array. I am using VS2008, aspnet, c# 3.5, sqlserver 2005. Am I better off Option 1. Making 1 call to a stored procedure in sqlserver from c# code, and then doing all t...

DCount vs. SQL SELECT COUNT(*)?

I am trying to get a count of all items sent to a supplier based on the purchase order they are assigned to. But I can't seem to get the control to show a number of items based on the purchase order instance - it keeps throwing either a #name? or #error! message in the text box when the form is activated. Create statement for tblPODeta...

In a Data Warehouse scenario is there any disadvantage to using WITH(NOLOCK)

I have a Kimball-style DW (facts and dimensions in star models - no late-arriving facts rows or columns, no columns changing in dimensions except expiry as part of Type 2 slowly changing dimensions) with heavy daily processing to insert and update rows (on new dates) and monthly and daily reporting processes. The fact tables are partiti...

MS SQL Server 2005 - Stored Procedure "Spontaneously Breaks"

A client has reported repeated instances of Very strange behaviour when executing a stored procedure. They have code which runs off a cached transposition of a volatile dataset. A stored proc was written to reprocess the dataset on demand if: 1. The dataset had changed since the last reprocessing 2. The datset has been unchanged for 5 ...

How do I read inconsistent nvarchar data as decimal data

For SSRS 2005 report how do i read inconsistent nvarchar data values from database as consistent numeric decimal data for plotting a line chart? the nvarchar column has lab readings to be plotted on a graph as nvarchar(15) datatype. sample column with inconsistent data as shown sample columnvalues: 00123 102 (NULL) 333 456 N/R No Resu...

No database connectivity from within Windows Service

Hi folks, I'm trying to write a service in CBuilder 6 (target XP Pro). Part of this service's job is to monitor and update a table on a database. We use direct ODBC to connect to the database, but the problem is happening with ADO as well, so we'll use that for simplicities sake. You can see my code below. This is called from a func...

SQL Server as a Web Serivce Client

Suppose given a URL, http://test.org/service.asmx How can I use SOAP method in SQL Server to access the service? ...

Mysterious CPU Activity in MS SQL 2005

I am looking at the activity monitor in MS SQL Management Studio 2005, and I see an entry from a login that I created, and it's using the tempdb, and the last command is always "SELECT INTO". And everytime I hit "Refresh" in activity monitor, that entry's "CPU" column goes up by like 60. The "program" of that activity is "MS SQL Manageme...

How do I read inconsistent nvarchar data as decimal data

For SSRS 2005 report how do i read inconsistent nvarchar data values from database as consistent numeric decimal data for plotting a line chart? the nvarchar column has lab readings to be plotted on a graph as nvarchar(15) datatype. sample column with inconsistent data as shown columnvalues 00123 102 (NULL) 333 456 N/R No Result 567 ...

How to connect a new query script with SSMS add-in?

I'm trying to create a SSMS add-in. One of the things I want to do is to create a new query window and programatically connect it to a server instance (in the context of a SQL Login). I can create the new query script window just fine but I can't find how to connect it without first manually connecting to something else (like the Objec...