sql-server

What is the difference between a unique constraint and a unique index

What is the difference between the following two statements? alter table [dbo].[Demo] add constraint [UC_Demo_Code] unique ( [Code] ) go create unique nonclustered index [UK_Demo_Code] on [dbo].[Demo] ( [NB_Code] ) go Does the constraint have an index to help it enforce uniqueness, or will a table scan be performed on every insert/upd...

Asp.net Report Viewer - Custom filter parameters

Hi all, for a data warehouse project I need to know about some best practices regarding custom report viewer filters/parameters. Usually I use the standard parameter feature for reports, like multiple select boxes, check boxes, text boxes etc.. But for the current project some reports require more complex report parameters. E.g. a user...

How do you manage your sqlserver database projects for new builds and migrations?

How do you manage your sql server database build/deploy/migrate for visual studio projects? We have a product that includes a reasonable database part (~100 tables, ~500 procs/functions/views), so we need to be able to deploy new databases of the current version as well as upgrade older databases up to the current version. Currently we...

SQL Recursive Calculated Date

I have a sql server table: CREATE TABLE [Workflow].[MilestoneDate]( [MilestoneDateId] [int] IDENTITY(1,1) NOT NULL, [SpecifiedDate] [datetime] NULL, [RelativeDays] [int] NULL, [RelativeMilestoneDateId] [int] NULL, CONSTRAINT [PK_MilestoneDate] PRIMARY KEY CLUSTERED ( [MilestoneDateId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NOREC...

CreateProcess from NT service hangs

I'm trying to start SQLServer2008SP1 express installer from the NT service process. Process is started successfully, I can see it in task manager, but it does nothing, just stays inactive until I kill him. I'm starting the process with the following command: szCmdLine = "Setup.exe /Q /HIDECONSOLE /ACTION=install /CONFIGURATIONFILE=Con...

Large Product catalog with statistics - alternatives to Sql Server?

I am building UI for a large product catalog (millions of products). I am using Sql Server, FreeText search and ASP.NET MVC. Tables are normalized and indexed. Most queries take less then a second to return. The issue is this. Let's say user does the search by keyword. On search results page I need to display/query for: Displ...

SQL: How can i update a value on a column only if that value is null?

Hey, I have an SQL question which may be basic to some but is confusing me. Here is an example of column names for a table 'Person': PersonalID, FirstName, LastName, Car, HairColour, FavDrink, FavFood Let's say that I input the row: 121312, Rayna, Pieterson, BMW123d, Brown, NULL, NULL Now I want to update the values for this person, b...

SQL Server 2005 Weird varchar Behavior

This SQL Server 2005 T-SQL code: DECLARE @Test1 varchar; SET @Test1 = 'dog'; DECLARE @Test2 varchar(10); SET @Test2 = 'cat'; SELECT @Test1 AS Result1, @Test2 AS Result2; produces: Result1 = d Result2 = cat I would expect either The assignment SET @Test1 = 'dog'; to fail because there isn't enough room in @Test1 Or the SELECT to...

SSRS Forms Authentication - Report Builder Login

Hello, I'm using SSRS 2005, with custom forms authentication module. That works great. But the report builder prompts for credentials, is there a way to get around this? Is this a configurability thing? Thanks. ...

Merge replication server side foreign key violation from unpublished table

We are using SQL Server 2005 Merge Replication with SQL CE 3.5 clients. We are using partitions with filtering for the separate subscriptions, and nHibernate for the ORM mapping. There is automatic ID range management from SQL Server for the subscriptions. We have a table, Item, and a table with a foreign key to Item - ItemHistory. Bot...

Easiest way to make copy SQL Server DB to test DB?

What is the easiest way to take a SQL Server database and make a test copy of it? I have looked through some existing topics but not sure if there is an easier way. I have database publisher. I want to be able to keep both database on the same server, potentially. Update: I used the Microsoft SQL Server Publishing Wizard to script to f...

Query Results Differ In SQL Mgmt and CFQuery

executing the following query in SQL management studio provides results, whereas it does not via cfquery... select distinct locationid, locationname, locationaliasname from vwLocationsWithAlias where 1 = 0 or (LocationName = N'the' or LocationAliasName = N'the') or (LocationName = N'the republic' or LocationAliasName = N'the republic') ...

Alter stored procedure if condition is met

I am looking to alter a stored procedure if a condition exists. I want to leave the stored procedure as is if the condition is not met, so drop/create is not really an option. Trying to put the contents of ALTER PROC inside an IF block is throwing up errors for me. Any thoughts? ...

Updating Database From Dataset?

I wanna update my database from my dataset. mydataadapter = new MySqlDataAdapter("SELECT * FROM table0; SELECT * FROM table1; SELECT * FROM table2;", con); myda.Fill(dataset); //...... // for example I'm doing a change like this ds.Tables[2].Rows[1][3] = "S"; //Then updating the database MySqlCommandBuilder com = new MySqlCommandBuild...

Consolidating values in a junction table

I have the following schema: Parcels Segments SegmentsParcels ========= ========== ================= ParcelID SegmentID ParcelID ... Name SegmentID ... id A user of the data wants to consolidate Segments.Names and gave me a list of current Segment.Names ma...

Query MS SQL and sent results to MY SQL DB

Hi I need to create a script which will run on Windows 2003 and Windows 2008 servers to query the locally installed MS SQL Server (2005 and/or 2008) and then write the results to a MYSQL DB on the Internet. Any ideas how to create this? should I use vbscript? or a stored proc? ...

Raw SQL sent to SQL Server from .NET on stored procedure call

Is there a way to get the raw text that is sent to SQL Server, as seen in SQL Profiler, from the ADO.NET call? using(SqlConnection conn = new SqlConnection(connString)) { SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "GetSomeData"; cmd.Parameters.Add("@id").Value ...

Managing multiple customer databases in ASP.NET MVC application

I am building an application that requires separate SQL Server databases for each customer. To achieve this, I need to be able to create a new customer folder, put a copy of a prototype database in the folder, change the name of the database, and attach it as a new "database instance" to SQL Server. The prototype database contains all...

Database design for invoices, invoice lines & revisions

I'm designing the 2nd major iteration of a relational database for a franchise's CRM (with lots of refactoring) and I need help on the best database design practices for storing job invoices and invoice lines with a strong audit trail of any changes made to each invoice. Current schema Invoices Table InvoiceId (int) // Primary key Job...

SSMS Results to Grid - CRLF not preserved in copy/paste - any better techniques?

When I have a result set in the grid like: SELECT 'line 1 line 2 line 3' or SELECT 'line 1' + CHAR(13) + CHAR(10) + 'line 2' + CHAR(13) + CHAR(10) + 'line 3' With embedded CRLF, the display in the grid appears to replace them with spaces (I guess so that they will display all the data). The problem is that if I am code-generating ...