sql-server-2005

Best optimizing for a large SQL Server table (100-200 Mil records)

What are the best options/recommendations and optimizations that can be performed when working with a large SQL Server 2005 table that contains anywhere from 100-200 Million records? ...

SQL Server Delete - Froregin Key

I have got two tables in Sql Server 2005: USER Table: information about user and so on. COUNTRY Table : Holds list of whole countries on the world. USER_COUNTRY Table: Which matches, which user has visited which county. It holds, UserID and CountryID. For example, USER_COUNTRY table looks like this: ID -- UserID -- CountryID 1 -- 1 ...

Finding all Stored procedures calling a function

Hi, How can I find out all the stored procedures that are calling a particular user defined function in SQL Server 2005. Or how to assign a defult value to a parameter in a user defined function so that when a stored procedure calls that function and does not pass any value to that parameter function assumes the default value. Regards...

How do I introspect on a SQL Server?

I have a server with a vendor application which is heavily database-reliant. I need to make some minor changes to the data in a few tables in the database in an automated fashion. Just INSERTs and UPDATEs, nothing fancy. Vendors being vendors, I can never be quite sure when they change the schema of a database during upgrade. To tha...

Output columns not in destination table?

SUMMARY: I need to use an OUTPUT clause on an INSERT statement to return columns which don't exist on the table into which I'm inserting. If I can avoid it, I don't want to add columns to the table to which I'm inserting. DETAILS: My FinishedDocument table has only one column. This is the table into which I'm inserting. FinishedDocum...

sql - How do I enforce a two-column constraint?

I have a CustomerID column and an EffectiveDate column in a table. I need the combination of these two to be unique. However, I already have a primary key on an auto-numbered integer column. What is a good way to accomplish my goal? Thanks ...

Why would you commit a transaction within a catch clause?

Microsoft has the following example for try...catch in tsql: USE AdventureWorks; GO -- SET XACT_ABORT ON will render the transaction uncommittable -- when the constraint violation occurs. SET XACT_ABORT ON; BEGIN TRY BEGIN TRANSACTION; -- A FOREIGN KEY constraint exists on this table. This -- statement will genera...

schema for storing different varchar fields over time?

This app I'm working on needs to store some meta data fields about an entity. The problem is that we can already foresee that these fields are going to change a lot in the future. Right now every entity's property is translated to one column in the entity table, but altering table columns later down the road will be costly and error-pr...

SQL Aggregate all Purchases for a certain product with same rebatecode

I would like to aggregate all purchases for a certain product that used the same rebatecode (using SQL Server 2005). Assume we have the following table: ID ProductID Product RebateCode Amount 1 123 7HM ABC 1 2 123 7HM XYZ 2 3 124 7HM ABC 10 4 124 ...

Handling Timeouts In A Website SQLCommand Object and c#

I'm using visual studio 2008 and sql server 2005 and everything is working just fine under normal use. However if a user is on a page for a while several minutes with no activity then clicks a button on occassion the site throws the following exception ... Procedure or Function "sp_name" parameter '@SomeParameterName', which was not su...

SQL - SSMS2005 - How do I copy a database diagram to another database?

Is there a simple method for copying a database diagram from one database server to another? I have a diagram on a development server that needs to be moved to the production server. Thanks (Sql server 2005, SSMS2005 Express) ...

SQL Function for On Balance Volume (Financial Query)

I would like to create a function for On Balance Volume (SQL Function). This is too complex of a calculation for met to figure out but here is the outline of the User Defined Table Function. If someone could help me to fill in the blanks I would appreciate it. Craig CREATE FUNCTION [dbo].[GetStdDev3] (@TKR VARCHAR(10)) RETURNS @r...

Moving from NHibernate to FluentNHibernate: assembly error (related to versions)?

Not sure where to start, but I had gotten the most recent version of NHibernate, successfully mapped the most simple of business objects, etc. When trying to move to FluentNHibernate and do the same thing, I got this error message on build: "System.IO.FileLoadException: Could not load file or assembly 'NHibernate, Version=2.1.0.4...

Insert Stored Procedure does not Create Database Record

Hello All, I have the following stored procedure: ALTER PROCEDURE Pro_members_Insert @id int outPut, @LoginName nvarchar(50), @Password nvarchar(15), @FirstName nvarchar(100), @LastName nvarchar(100), @signupDate smalldatetime, @Company nvarchar(100), @Phone nvarchar(50), @Email nvarchar(150), @Address nvarchar(255), @Pos...

Database Backup

Scenario i want to take backup from 7 client database to 1 server database. i dont know structure of the db { either server or client db }. both databases are having old data. now i have to make the tool take the backup for that. and should possible to backup old data also[if any updates done on old data.] please help to find the soluti...

How to create DSN for SQL Server using C# ?

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; using System.Data.SqlClient; using Microsoft.Win32; usin...

FluentNHibernate error -- "Invalid object name"

I'm attempting to do the most simple of mappings with FluentNHibernate & Sql2005. Basically, I have a database table called "sv_Categories". I'd like to add a category, setting the ID automatically, and adding the userid and title supplied. Database table layout: CategoryID -- int -- not-null, primary key, auto-incrementing UserID --...

bulk insert to SQL Server, insert statements vs one insert XML statement?

The application layer (ColdFusion) needs to insert multiple rows into SQL Server 2005. I was thinking of using loop in app layer to construct multiple input statements and send to SQL Server over JDBC in a single connection. My colleague however suggests to construct an XML and bulk insert the XML instead. Which one is the better me...

How to get numeric random uniqueid in SQL Server

I am using SQL Server 2005, please tell me how can I get 6 digits (unique numeric which should be random) value for every row in table. I have a field in table in which I need 6 digit numeric value (random and unique). Please help me to do this. ...

Outlook Macro not executing

Hello all, we are using an an outlook macro for incoming emails to unzip the attachments, log them in sql server and copy them to a special working folder where a windows service processes them. The problems are: the user must be logged in at the server otherwise the macro wont run. I think there is no workaround for ...