sql-server-2008

SQL Server 2008 - Update a temporary table

Hello, I have stored procedure in which I am trying to retrieve the last ticket completed by each user listed in a comma-delimited string of usernames. The user may not have a ticket associated with them, in this case I know that i just need to return null. The two tables that I am working with are defined as follows: User ---- UserNam...

SQL Server Composite Primary Keys

I am attempting to replace all records for a give day in a certain table. The table has a composite primary key comprised of 7 fields. One such field is date. I have deleted all records which have a date value of 2/8/2010. When I try to then insert records into the table for 2/8/2010, I get a primary key violation. The records I am att...

Does SQL Server guarantee sequential inserting of an identity column?

In other words, is the following "cursoring" approach guaranteed to work: retrieve rows from DB save the largest ID from the returned records for later, e.g. in LastMax later, "SELECT * FROM MyTable WHERE Id > {0}", LastMax In order for that to work, I have to be sure that every row I didn't get in step 1 has an Id greater than Last...

SQL Server 2008 database engine login failed for administrator user in windows 7

I installed SQL Server 2008 Enterprise Edition on Windows 7 Ultimate from sadegh user. This account exists in administrators role. after a few days I removed sadegh user from Windows and now I am using administrator user. But I can't login to SQL Server database engine using Windows authentication method and I receive this error messag...

Tools, scripts for working with SQL Server 2008

Hi, While working with DB, I find useful using some tools, that help me to solve DB problems. Some of them are: 1) Insert generator 2) A tool that can execute a script on a list of DB's 3) Finding a text in stored procedures and functions. 4) DB Back up scripts My question is, what are most useful tools, scripts(anything else), ...

Hiding Table Rows

I have a table that I'm using to show details from the line items of a quote. I want to hide a particular row depending on the value of the field in it. The expression I've tried is to set the row visibility to: =IIF(isnothing(First(Fields!NEW_PRICEBREAKS.Value, "QuoteDetail")),true,false) When I run the query from the dataset "Null"...

Is it possible to definitively identify whether a DML command was issued from a stored procedure?

I have inherited a SQL Server 2008 database to which calling applications have access through stored procedures. Each table in the database has a shadow audit table into which Insert/Update/Delete operations for are logged. Performance testing on populating the audit tables showed that inserting the audit records using OUTPUT clauses w...

How do I eliminate Error 3002?

Say I have the following table definitions in SQL Server 2008: CREATE TABLE Person (PersonId INT IDENTITY NOT NULL PRIMARY KEY, Name VARCHAR(50) NOT NULL, ManyMoreIrrelevantColumns VARCHAR(MAX) NOT NULL) CREATE TABLE Model (ModelId INT IDENTITY NOT NULL PRIMARY KEY, ModelName VARCHAR(50) NOT NULL, Description VARCHAR(200) NULL) CR...

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 ...

How to user prefix 'N' for unicode with nvarchar variable in SQL Server?

How to user prefix 'N' for unicode with nvarchar variable in SQL Server? For example: Given this variable: declare @Query1 nvarchar(max) I can assign to it like this: set @Query1 = N'لاحظات' But what if I want to use N@Query1 somewhere? ...

Table-Valued Parameter in Stored Procedure and the Entity Framework 4.0

Hi there, I have a stored procedure in SQL Server 2008 called 'GetPrices' with a Table-Valued Parameter called 'StoreIDs'. This is the type i created for this TVP: CREATE TYPE integer_list_tbltype AS TABLE (n int) I would like to call the SP from my Entity Framework. But when I try to add the Stored Procedure to the EDM, i get the f...

Ensuring Database Integrity when Adding and Deleting

As I am developing my database, I am working to ensure data integrity. So, for example, a Book should be deleted when its Author is deleted from the database (but not vice-versa), assuming one author. When I setup the foreign-key, I did set up a CASCADE, so I feel like this should happen automatically if I perform a delete from LINQ. ...

C# Dataset Dynamically Add DataColumn

I am trying to add a extra column to a dataset after a query has completed and populate that new column with data. I have a database relationship of the following: EmployeeGroups / \ Groups Employees Empoyees holds all the data for that individual, I'll name the unique key the UserID. Groups holds all the ...

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) ...

Remote Server access/login problem

My OS is Windows Server 2008 Enterprise. I have installed SqlServer 2008. In network i want to access Other users Server,i have already enable remote access,when i try to login show bellow error **Connection can not TITLE: Connect to Server ------------------------------ Cannot connect to TECHNO009. ------------------------------ ADD...

SQL Stored Procedure fails to update data while the script in it works manually

I have a SQL Script that I execute in a job to transform tables periodically. To speed it up I put that script in a stored procedure and executed it with a job. It worked faster. The problem occurs at times when the stored procedure even though it executes it doesn't work. I use the script manually and run it and everything works fine....

SQL Server cluster install issue

Hello everyone, I am going to install SQL Server 2008 Enterprise cluster on Windows Server 2008. I am wondering whether I have to setup a Windows domain (or active directory) in order to install SQL Server cluster? thanks in advance, George ...

T-SQL out of order insert

Basically I have a User-Defined Table Type (for use as a table-valued variable) which I'm referencing in a stored procedure that effectively just calls two other stored procedures, then inserts those values into the table type. Id est INSERT INTO @tableValuedVariable (var1, var2, var3, var4, var5) EXEC [dbo].StoredProcedure1; ...

Lock record before updating?

Is there any disadvantage of locking a record before updating it? ...

SQL Server 2008 stored procedure result as column default value

First of all, thank you guys. You always know how to direct me when I can't even find the words to explain what the heck I'm trying to do. The default values of the columns on a couple of my tables need to be equal the result of some complicated calculations on other columns in other tables. My first thought is to simply have the column...