sql-server-2005

Alter composite key to include newly added column in sql server 2005

I have a table GB_Assignor_Assignee. I have a primary key which includes this combination(StateCode, CountyID, Doc_Type_Group_Code). Now i have to add a new column Doc_Type_Code. I added it by altering table. I want to include this new column inside this primary key.So my combination will be(StateCode, CountyID, Doc_Type_Group_Code,Doc_T...

Get a single parent with all children in a single row

Let's asume I have a parent-child structure setup in SQL (server 2005): CREATE TABLE parent (Id INT IDENTITY PRIMARY KEY, Name VARCHAR(255)) CREATE TABLE child (Id INT IDENTITY PRIMARY KEY, parentId INT, Name VARCHAR(255)) insert into parent select 'parent with 1 child' insert into parent select 'parent with 2 children' insert into ch...

Creating a database in SQL Server 2005

After installing SQL Server 2005, I tried to create a new database (command: create database database_name). But the message was an error: permission denied to create a database in 'master' database. My question is 1.) how to exit this master database and create a new database outside it, 2.) what is a master database. ...

Add total to group.

I have a Order Details table. What I want to do is create 1 query to show OrderNumber | SKU | QTY | Price | Line Total | 1 SKU1 1 10.00 10.00 1 ---- 0 0.00 10.00 2 SKU1 2 10.00 20.00 2 SKU2 3 1.50 4.50 2 ---- 0 0.00 ...

Creating audit triggers in SQL Server

I need to implement change tracking on two tables in my SQL Server 2005 database. I need to audit additions, deletions, updates (with detail on what was updated). I was planning on using a trigger to do this, but after poking around on Google I found that it was incredibly easy to do this incorrectly, and I wanted to avoid that on the ...

Need help with Scalar-valued function in SQL Server 2008

Hello, I need help with this scalar-valued function. What I want to do is to return the value I get in MaxValue on the line max(Value) AS MaxValue. The query works and will only return 1 value if ItemId and ListPropertyId exists, but I am not able to create a function of it. CREATE FUNCTION GetLpivMax ( -- Add the parameters for ...

How much minimum rows require for eligibility to create index?

I have created script to find selectivity of each columns for every tables. In those some tables with less than 100 rows but selectivity of column is more than 50%. where Selectivity = Distinct Values / Total Number Rows So, are those column are eligible for index? Or, can you tell, how much minimum rows require for eligibility to create...

SQL Server: Doing a DELETE with a complex VIEW.

I have a complex VIEW and would like to use the DELETE verb against it. Can this be done? Will the DELETE verb only affect the FROM table used in the SELECT statement? I have about 8 joins. Will any of these joined tables be affected? I am using SQL Server 2005. ...

How can I use pixels in Visual Studio instead of inches?

I'm making reports in Business Intelligence Designer Studio (VS 2005). My reports will be viewed primarily on the screen, and I'd like to change my ruler to pixels instead of inches. Is this possible? ...

Pymssql: Calling Stored Procedure with parameters

I am using pymssql to make database calls to a SQL 2005 database. I want to pass parameters to a stored procedure. I am having a hard time getting the correct syntax for that. Here is what I have for calling a procedure with no parameters: import _mssql connection = _mssql.connect(server='myserver', database='mydatabase', trusted=True) ...

Finding complement date ranges?

I have two tables both of which have columns StartDate and EndDate. I'm trying to return a single resultset that contains all date ranges from one table (TableA), and all complement date ranges from the other one (TableB). CREATE TABLE [dbo].[TableA]( [ID] [int] NOT NULL, [StartDate] [datetime] NOT NULL, [EndDate] [datetime...

SQL Query re-write help

I need to rewrite the query below so that it is as efficient as possible. Any suggestions on how to increase the performance of this query? I plan on setting columns t2_1 and t2_2 to not nullable and assigning a default value, I'm mainly curious as to if/how I can modify the join so that I can move the "WHERE ... IN ... " sections ther...

new_time function in SQL Server 2005

Is there a function or a workaround in SQL Server 2005 that is equivalent to the new_time() function in oracle? ...

tsql- to find when was the database taken offline

Is there a way how we can know when was a database taken offline? Platform: SQL server 2005 ...

Overhead of opening connection

When a connection to DB is opened using C# OPEN statement, does that impact the web server performance or only the Database? So, how does the repeated opening and closing of the database connection impact the web server and the database. Can somebody please give me some insight on this. Thanks. ...

Please help me convert a Linq Query to a SQL Query... Desperate...

Hey all, Im pretty proficient in LINQ, but not in SQL. I understand cursors are horrible and shouldn't be used. I know SQL Syntax pretty well, but I am trying to figure out how to convert this query and update to SQL from Linq. I don't know how to go through the Foreach of SQL without using cursors and Im a bit lost on what to do ne...

Slim but long SQL Server 2005 Table

Hi, I have an SQL table with the following structure: Code1 - int Code2 - int Val1 - real Val2 - real Val3 - real There is only one index (clustered) were Code1 is the first indexed column and Code2 is the second. The size of a single record is 20bytes. I need to be able to store around 150,000,000 records and the biggest select ...

What is the best way to delete large database programmatically

I need to drop a perticular database in SQL Server 2005 using T-SQL. I know droping a databse can not be done in a database trnsaction. So what if while deleting a real huge database some unexpected exception occurs E.g. Time out exception. Will it leave my database in unstable state ? If yes, how do i avoid such situation ? ...

Building SQL Query

Hi all, I need some help to build SQL Query. I have table having data like: ID Date Value1 Value2 Code 1 12/01/2009 4 3.5 abc 2 12/02/2009 3 4.0 abc 3 11/03/2009 6 8.5 xyz 4 11/01/2009 2 5.5 abc 5 11/02/2009 4 6.0 xyz 6 12/03/2009 5 7.0...

Product groups - Better data model? New paradigm for implementation?

Apologies for the less than ideal title; had a hard time coming up with something. Three entities: Products, Clients and Client_Product_Authorization. A Client has access to many Products. A Product is accessed by many Clients. A Client_Product_Authorization authorizes a Client to access a Product. We have 100,000+ Products (virtual...