sql-server

Designing a comment table

Basically I want to create a comment system where comments may have parents that are also comments BUT I would also like them to potentially have parents that may be something else, such as users or products (ie, I want to be able to comment on products, users, other comments, or practically any resource) How should I do that? Current ...

Create an index on SQL view with UNION operators? Will it really improve performance?

I am trying to create an index on the following view: SELECT 'Candidate' AS Source, CandidateID AS SourceId, LastName + ', ' + FirstName AS SourceName FROM dbo.Candidates UNION SELECT 'Resource' AS Source, ResourceID AS SourceId, LastName + ', ' + FirstName AS SourceName FROM dbo.Resources UNION SELECT 'Deal'...

Compress data from Database

Quick q, could be a silly one given my (lack of) findings on Google so far. I have a Database. In this database is a Table with some Data. The Data is a large BLOB but can't be compressed (for reasons out of my control). I have an Application that talks to this Database. I would really like to be able to ensure that the Data is comp...

SQL Server 2005 xp_cmdshell problem

The following code works fine when executed directly in Sql server: DECLARE @cmd sysname set @cmd = 'dir "C:\A_Projects"' EXEC master..xp_cmdshell @cmd but when I try to create a stored procedure as follows: create procedure zz (@cmdin varchar(255)) EXEC master..xp_cmdshell @cmdin I get a message 'Incorrect syntax near the keyword '...

Constraint for one-to-many relationship

We have a two tables with a one-to-many relationship. We would like to enforce a constraint that at least one child record exist for a given parent record. Is this possible? If not, would you change the schema a bit more complex to support such a constraint? If so how would you do it? Edit: I'm using SQL Server 2005 ...

Performance Difference between LINQ and Stored Procedures

Related LINQ-to-SQL vs stored procedures? I have heard a lot of talk back and forth about the advantages of stored procedures being pre compiled. But what are the actual performance difference between LINQ and Stored procedures on Selects, Inserts, Updates, Deletes? Has anyone run any tests at all to see if there is any major diffe...

What is the best way to query data from multilpe tables and databases?

I have 5 databases which represent different regions of the country. In each database, there are a few hundred tables, each with 10,000-2,000,000 transaction records. Each table is a representation of a customer in the respective region. Each of these tables has the same schema. I want to query all tables as if they were one table. The...

SSIS - lookup surrogate key for parent

I have a table in my source DB that is self referencing |BusinessID|...|ParentID| This table is modeled in the DW as |SurrogateID|BusinessID|ParentID| First question is, should the ParentID in the DW reference the surrogate id or the business id. My idea is that it should reference the surrogate id. Then my problem occurs, in my data...

How to find the local instaces using SQLSERVER SMO??

Hi is there is any way to find out the local instaces installed in a single physical machine. scenario: Suppose i have installed sqlserevr2005 and sqlexpress on same machine.is there any way to find these instances using SMO.. and i have installed the datafiles of two instaces in different locations. how to find these datafiles locat...

SQL Server 2008: How crash-safe is a CLR Stored Procedure that loads unmanaged libraries

We've got a regular (i.e. not extended) stored procedure in SQL Server 2000 that calls an external exe. That exe, in turn, loads a .dll that came from an SDK and calls some procedures from it (i.e. Init, DoStuff, Shutdown). The only reason we have this external exe thing is because we didn't want to create an extended stored procedure t...

Round in MS SQL on 0.05 or 0.00

Hello I am coming from Bosnia and Herzegovina and in our county the smallest note bill is 0.05, Now the government pushing us to our retrial prices rounding on 0.05 or at 0.00. Therefor I want to create SQL Scalar Valued Function for rounding the prices on given value. Is there some build in solution so I can save resource of my querie...

Cannot retrieve output parameters from MSSQL stored procedure using PHP

I am executing a MSSQL stored procedure that is supposed to return an output parameter (ErrCode), as well as a resultset. I am calling the procedure from PHP using the following code, but so far have been unable to retrieve the output parameter: $stmt = mssql_init("addFaculty", $this->db); mssql_bind($stmt, "@FacultyID", $FacultyID, S...

SQL Command for generating schema text (similar to CreateTo or AlterTo)

SQL Server 2005. Is there a sql query that will return a text field containing the same type of schema info as you would find in doing a right click table -> Script Table As -> Create To (or Alter To) from SQL Server Management Studio ? I'm looking for a single/flat format that describes the entire table, including constraints, indices...

How to invert words in a column

I have a table with varchar(128) column with data like: word1, word2, , word3, word4 word1, word2, word3, , word1,,,, ; word2 ;word1 word2, word3 I have to update this table, making words reverse order: word4, ,word3,,word2 ,word1 ,,word3, ,word2, word1 Could you help me to do it using only single sql query?? ...

Guide for Replication in MS SQL Server 2008

I wonder if anyone know/have a good guide for Replication in MS SQL Server 2008? I want to set up a Replication between two different computers that run MS SQL Server 2008, the master runs on Windows Vista, and the slave will run on Windows XP. I´ve done this in earlier days, but between two MySQL-servers. ...

Open Source testing for SQL Server 2000 and 2005

Are there any open source testing tools for testing the Sql Server 2000 stress . ...

T-SQL field parsing

There is a field in a 3rd party database that I need to group on for a report I'm writing. The field can contain a few different types of data. First it could contain a 3 digit number. I need to break these out into groups such as 101 to 200 and 201 to 300. In addition to this the field could also be prefaced with a particular letter...

SQL Server 2005 Insert parent/child xml data

Given an xml document that looks like this here: <parentRecords> <parentRecord field1="foo" field2="bar"> <childRecord field1="test" field2="text" /> <childRecord field1="test2" field2="text2" /> </parentRecord> <parentRecord field1="foo2" field2="bar2"> <childRecord field1="test3" field2="text3" /> ...

Ensuring thread synchronization in SQL possible?

If I have several SPs SP1 SP2 some_inline_queries how do I ensure that they are all run at once without interruption from other threads? Is it possible to do this from SQL Server level? edit: Let's say we have a main script with 3 major actions: sp1 scans table t1 to generate a random string that is unique to column c1 in t1; s...

SQL Server 2000 blocking problem solved by running profiler?

We are working on a large Java program that was converted from a Forte application. During the day we are getting Blocking SPID's in the server. We had a DBA visit yesterday and he set up a profile template to run to catch the locking/blocking action. When we run this profile the blocking problem goes away. Why? This application is dist...