sql-server

OutofMemory exception when serializing complex objects

I have a web application that serialize a very complex object that has about 500 child objects to an SQL 2008 database. The problem is when the object is very large (more than 500 child objects) it generates an outofmemory exception and we need to restart the iis. I am using the binary serializer in the .NET to serialize the object into...

SQL Server FILESTREAM performance

SQL Server FILESTREAM has some known limitations. 1) Database mirroring does not support FILESTREAM. 2) For clustering, FILESTREAM filegroups must be put on a shared disk which defeats the purpose of creating the clusters. Given these limitations in FILESTREAM is it advisable to build a FILESTREAM solution. Im looking to save and retri...

T-SQL - In Single Stored procedure want to pass value(result) of one query to another query as input.

Hi All, I have a Stored procedure, in which I have to insert 3 strings into 3 different Tables at a time, each string into each of the 3 tables. In each table, a unique primary key (rowid) would be generated on insertion of the value. Now, the Primary Key of first two tables is the Foreign key of the Third Table which as you all know, sh...

If statement within switch

I know I'm just thinking of the logic all wrong here but how do I achieve the following: update @table set column1 = case when column1 <> '' then rtrim(column1) + ', ' + rtrim(column2)--if statement here else rtrim(column2) end ...

SQL 2000/2005/2008 - Find Unique Constraint Name for a column

Hi, I have a table with a column that needs the data type upgrading. However running any alter script causes errors due to a unnamed unique constraint. I need to drop this constraint but unfortunately I do not know the name. I have a script which currently lists all the unique constraints on the table but I need to find out how to go...

Test if Table has at least certain Stored Procedure, else fail test c#

This test checks if only one SP ends with Insert, Load, or Save, then it's successful. //Query to find SPs for a certain Table name string check_SP = "SELECT ROUTINE_NAME, ROUTINE_DEFINITION " + "FROM INFORMATION_SCHEMA.ROUTINES " + "WHERE ROUTINE_DEFINITION LIKE '%CLNT_" + Table_Name + "%' " + "AND ROUTINE_TYPE='PROCEDU...

Consecutive streak of dates

Hi, Hopefully this isn't a dupe of another question, but I couldn't see it anywhere else - also this is a simplified version of another question I asked, hopefully to get me started on working out how to approach it. I am looking to work out consecutive ranges of payments where there has been at least one payment in each month. I have ...

How to get unique rows from TSQL based on date open and closed

I have two tables this is data from one: ID ANS_ID USER_ID Date_Opened 06146723 858735205 55258 2009-02-20 12:59:47.0000000 06146723 481768765 55258 2009-09-16 17:04:22.0000000 and table 2: ID ANS_ID USER_ID Date_Closed 06146723 630993597 5258 2009-04-02 14:35:23.0000000 0614672...

java and jboss, with SQL server. Mulitple insert statements in a native query using entitymanager, not working; but does work in sql

String myQuery1 = "insert into mytable(mycol) values(myval) \ngo"; String myQuery2 = "insert into mytable(mycol) values(myval2) \ngo"; String myQuery = myQuery1 + myQuery2; Query query = myEntityManager.createNativeQuery(myQuery); List<?> insertResultList = queryInsertDefaults.getResultList(); using the eclpise debugger I can see th...

DROP CASCADE in Sql Server

I'm running a South migration in a Django project that uses Sql Server and pyodbc. This is backwards migration so the South is trying to delete a few of my tables. The South executes the following method in order to drop the tables: def delete_table(self, table_name, cascade=True): """ Deletes the table 'table_name'. """ ...

Why does new T-SQL of SQL Server 2008 work on database in compatability mode 80 ?

Experimenting with new features of T-SQL, I've run into a puzzle. Here is some new syntax supported by SQL 2008 and I'd expect it to work on databases set for compatibility mode 100 (i.e. 2008) and not work for compat mode 80 (i.e. 2000). Yet this works for a database set for SQL SERVER 2000 compatibility mode on a SQL 2008 instance of S...

Same measure ID/name conflict (SQL Server AMO)

I am currently importing two measure groups from two different cubes in a single new cube. There is a measure with the same name in the two cubes, when I import the measures in the new cube I get an error during cube processing because of the duplicate ID. How can I avoid this? I am using AMO to build the cube pro grammatically. (SQL Ser...

How can I get Client Side Recordset from Server side Recordset?

I just made a sql query through a component which returned me a server side recordset. Is there a way I can make it as a client side recordset? Creation of the recordset is not in my control. I am not going to need server side recordset again. Basically I want to minimize round trips to the server at the cost of client memory. What cou...

Update Records in SQL Server database

I am using Visual Studio 2008 for creating a Winforms app. I have connected a database to it called XStats. There is one table in it called XGames and in that table 2 fields, XIndex (the primary key field) and GameNumber. Using the following code I can add records to the database, the data is taken from a text box, but once added I canno...

Non-Trusted Constraints

I just learned, to my amazement, that foreign key constraints can be non-trusted. This occurs when a constraint is added using WITH NOCHECK. When a constraint is non-trusted, it isn't used by the query analyzer for query plan generation. See: http://sqlblog.com/blogs/hugo_kornelis/archive/2007/03/29/can-you-trust-your-constraints.as...

Can I get SSMS to switch to the Messages tab programatically?

I'm writing a fairly long running script, which prints progress messages as it goes. However, SQL Server Management Studio by default shows the resultset tab, not the messages tab, so the user will have to click the messages tab after starting the script to see the progress as it happens. Is there a way for my script to tell SSMS to s...

SQL USER_NAME() windows authentication.

When I logged in sql management studio with windows authentication and I run SELECT USER_NAME() I see the result as dbo. I would of thought that it would showed my user .... I more looking at the explaination to as why it returns dbo ...

Unused sql parameters - are they of any harm?

Consider the following code: Dim sql = "SELECT * FROM MyTable WHERE value1 = @Param1" If someCondition Then sql = sql + " AND value2 = @Param2" End If Dim cmd As New SqlCommand(sql, conn) cmd.Parameters.AddWithValue("@Param1", param1Value) cmd.Parameters.AddWithValue("@Param2", param2Value) Assuming that I built a complex sql sta...

Using T-SQL how do you calcualte a test grade percentage?

It what should be a simple task, or a simple google search, I have come up empty. I am trying to simply calculate a grade percentage. I am trying to use: Select round((133 / 150), 2) * 100 That results in 0. I am trying to calcualte to get a score of 89%. I have tried multiple combinations and I am beginning to think it is either too ...

How to pass in parameters to a SQL Server script called with sqlcmd?

Is it possible to pass parameters to a SQL Server script? I have a script that creates a database. It is called from a batch file using sqlcmd. Part of that SQL script is as follows: CREATE DATABASE [SAMPLE] ON PRIMARY ( NAME = N'SAMPLE', FILENAME = N'c:\dev\SAMPLE.mdf' , SIZE = 23552KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LO...