sql-server

Can a Microsoft SQL table have more than one Primary Key?

I was always curious but can't find a concise answer. Any help? ...

negative selection SQL Query

I have been tasked with returning a negative selection from our sql database. I'll define the criteria as best i can. Thus far I haven't crafted a query that has worked. Business Table [Bus Name] [Bus ID] Activity Table [Activity ID] [Bus ID] Activity Extension Table [Ext ID] [Activity ID] [Bus ID] I need the Business names for a...

How to update guid ID references when converting to identity IDs

I am trying to convert tables from using guid primary keys / clustered indexes to using int identities. This is for SQL Server 2005. There are two tables MainTable and RelatedTable, and the current table structure is as follows: MainTable [40 million rows] IDGuid - uniqueidentifier - PK -- [data columns] RelatedTable [400 million row...

Best Approach to Processing SQL Data problem

I have a Data intensive problem which requires a lot of massaging and data manipulation and I'm putting this out there to see if anyone has an idea as to how to approach it. In simplest form. I have a lot of tables which can be joined together to give me a price listing for dentists and how much each charges for a procedure. so we hav...

How to call sp_help [table] for SQL Server when using Oracle SQL Developer as my client

I am using Oracle SQL Developer in a linux environment to connect to an SQL Server 2005. I don't seem to be able to make a sp_help [table_name] call. Previously, I found it quite useful when I was on a Windows environment using SQL Server management, and could make that call. Is there any way to do this? [edit] error message returned ...

Insert Concurrency Issue - Multithreaded Environment

I have an issue that the same stored procedure is being invoked at exactly the same time with exactly the same paramenters. The purpose of the stored procedure is to fetch a record if it exists or to create and fetch the record if it does not exist. The problem is that both threads are checking the existence of the record and reporting...

"Failed to lock variable" SSIS error

I am getting an error randomly for a scheduled SSIS package which runs hourly. The funniest thing is that if I delete the checkpoint file and run the package again it works fine but the error may show up at a future run. I have no clue why this is happening. Here is the full error message. Executed as user: UserNameChanged. Microsoft...

Query to collect data from previous rows

I have a table with records as, in example data below a CO.Nr are TH-123,Th-456 and so on... I need to collect the data.. Nr. CO.Nr Employee Resp Description Date 1 TH-123 ABC NULL HELLO 10.05.2010 2 TH-123 NULL S14 ...

SQL Server row level triggers

I tried to achieve row level delete trigger by using cursor but when in trying yo delete the any row from table it tooks so long time. I could not understand where exactly it stuck. /****** Object: Trigger [delStudent] Script Date: 06/24/2010 12:33:33 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TRIGGER [delStud...

Entity Framework 4 many to many doesn't delete the actual entity

I have an EF4 model over a SQL Server 2008 db. In my model I have a many to many relationship: Articles * - * Comments and Projects * - * Comments In my Model, I simply created an association and set it up to many to many. In my db, I then get two additional tables ArticleComments and ProjectComments, which only hold the primarykeys...

Split date range into intervals and count seconds in each interval in t-sql

I have a query I am trying to make on a table that has multiple entries for people with a start time and an end time e.g.: name,startime,endtime ('richard','2010-04-21 08:01:15','2010-04-21 08:06:15'), ('bill','2010-04-21 08:07:45','2010-04-21 08:11:15') What I need to do is create a report showing the seconds of each entry within each...

what is a .mdf and .ldf file

can anyone explain it in simple words relating to Microsoft SQL Server Management studio-what is a .mdf and .ldf file. ...

Step into stored procedure - canceled by user

Hi, I am trying to debug a long stored procedure in Visual Studio 2008. I have followed all the steps on this link: http://www.sqlteam.com/article/debugging-stored-procedures-in-visual-studio-2005 but I still get the same error... 'Canceled by user' and it never hits the breakpoint. Visual Studio 2008 and SQL Server 2005 are runnin...

concatenating 2 rtf fields stored in blobs with a sql script

I need to concatenate 2 rtf fields stored in 2 separate blob columns (actually they are nvarbinary(max) in sql server). I need to do this with a database script, not in an application. Is there a way? Or the only solution is to remove all the rtf headers, concatenate the "body" of the 2 fields and then recreate the headers? By headers...

SQL Server 2005 - how to shrink the tempdb

Hi, My tempdb size is growing too much, as we are doing too many transactions in the database. Can someone let me know how to shrink this tempdb without restarting the server. I have tried DBCC SHRINKDATABASE and it didn't help Thanks in advance ...

Searching a database from datatype

I've actually forgotten that in which table of my database I've stored my images as binary I have 300 tables and I can't check manually. I even don't remember the column name of the image section. Is there any query so that i can find my images and its corresponding table which contains that images.. Thanks for help in advance ...

Replace IN with EXISTS or COUNT. How to do it. What is missing here ?

I am using IN keyword in the query in the middle of a section. Since I am using nested query and want to replace In with Exists due to performance issues that my seniors have told me might arise. Am I missing some column, what you are looking for in this query. This query contain some aliases for readibility. How can I remove it. S...

SQL Server 2008 maximum size on FAT32

Hi all, I am running WinXP with a FAT32 file system. Does FAT32's max. file size limit of 4GB apply on the max. database size I can have? (I have SQL Server 2008 Developer Edition, I know the free editions restrict DB size to 4GB, having nothing to do with the file system) Thanks for any info ...

SQL Server Analysis Services: Add Column to provide Sub-Total of row's group

Hi There, Please find below my current SQL Query. What I'm trying to accomplish is add a column to the resultset that for each row provides the sub-total of the group that it belongs to. Can anyone provide me with an elegant solution to do this? SELECT costs.cost_des, SUM(costs_periods.actual) AS actual, SUM(costs.commitment) AS co...

SQL - Converting char to exact length varchar

I am trying to do something like this: SELECT CAST(MYCHARCOL AS VARCHAR(LEN(MYCHARCOL))) FROM MYTABLE How do I convert a char column to varchar that is the exact length of the data inside that char column? ...