sql-server

Does NHibernate support MsSql2008? Can it convert SQL XML DataType to XElement properties?

I couldn't find an answer - does NHibernate supports MsSql2008? For example - can it convert sql XML data type to .NET XElement? MsSqlConfiguration. shows only MsSql2005, MsSql2000 and MsSql7. ...

Custom sort in SQL Server

Hi, I have a table where the results are sorted using an "ORDER" column, eg: Doc_Id Doc_Value Doc_Order 1 aaa 1 12 xxx 5 2 bbb 12 3 ccc 24 My issue is to initially set up this order column as efficiently and reusably as possible. My initial take was to set up a scal...

I have a database diagram in Microsoft Visio how can i import it to Sql Server 2005?

I have done a database diagram in Microsoft Visio but I don't know how to import it to Sql Server 2005? By the way, which is the best tool you think you can use to do database diagrams, and that allows you to import it to Sql Server? ...

How can i join #Temp with sql table?

How can i join ( or union) #Temp with scr_SecuristLog Time. Look please [Time] column CREATE TABLE #Temp (VisitingCount int, [Time] int ) DECLARE @DateNow DATETIME,@i int,@Time int set @DateNow='00:00' set @i=1; while(@i<48) begin set @DateNow = DATEADD(minute, 30, @DateNow) set @Time = (datepart(hou...

Making primary key and identity column after data has been loaded.

I have quick question for you SQL gurus. I have existing tables without primary key column and Identity is not set. Now I am trying to modify those tables by making existing integer column as primary key and adding identity values for that column. My question is should I first copy all the records from the table to a temp table before m...

Select n random rows from SQL Server table

I've got a SQL Server table with about 50,000 rows in it. I want to select about 5,000 of those rows at random. I've thought of a complicated way, creating a temp table with a "random number" column, copying my table into that, looping through the temp table and updating each row with RAND(), and then selecting from that table where the ...

Creating SQL Server 2008 Add-Ons: current equivalent of sqlwb.exe

I'm trying to create a simple Add-On for SQL Server 2008; it is simply going to pass a parameter from SQL 2008 to a console application. Although Add-Ons are not specifically supported, according to these articles (1, 2), it is possible in 2005 and I'm assuming also in 2008. However, I've fallen almost at the first hurdle; I can't seem ...

Persistent Layer Validations

While saving data using a stored procedure often we encounter foreign key constraints, unique key constraints, etc. All such errors can be corrected by passing in the right data. Validation can be done in the business logic layer and should be sent to the persistence layer only if it succeeds. But in some cases it is convenient to valid...

Relational database design pattern question - Massive Read Only database

I have an interesting challenge of building a database that imports data from about 500 different sources. Each source has their own schema, and many are very very different. However, they all are data about a common entity. My first thought is a typical entity / Attribute / Value schema, however after converting the denormalized impo...

SQL Server 2005 Delete Trigger select from deleted returns null

I have a table called hl7_lock in SQL Server with these columns: hl7_id lock_dtm lock_user I have 3 triggers on the table for UPDATE, INSERT, and DELETE The table is never updated, but INSERT trigger is working perfectly. However this delete trigger occasionally puts a record in hl7_lock_log with a null hl7_id SET NOCOUNT ON; de...

Is it possible to update a binary field in SQL Server?

I know how to insert a new row into a table that has a binary column. But is there any way to update the binary column once that row has been added? So far an exhaustive google search has turned up nothing. MY solution so far is this Get the current row that I wish to update delete the row that I wish to update Create a new row with t...

SQL Server Management Studio Display Database Diagrams (ER) Permissions

I was wondering if anybody knew exactly what permissions where needed on a database in SQL Server 2005+ so that when a person uses SQL Server Management Studio, they could then be able to at minimum see the Database Diagrams. I have tried giving the person db_datareader, db_datawriter, and db_ddladmin, but to no avail. I have also tr...

How to manage "groups" in the database?

I've asked this question here, but I don't think I got my point across. Let's say I have the following tables (all PK are IDENTITY fields): People (PersonId (PK), Name, SSN, etc.) Loans (LoanId (PK), Amount, etc.) Borrowers (BorrowerId(PK), PersonId, LoanId) Let's say Mr. Smith got 2 loans on his name, 3 joint loans with his wife,...

How to insert into a table with just one IDENTITY column

(Came up with this question in the course of trying to answer this other one) Consider the following MS-SQL table, called GroupTable: GroupID ------- 1 2 3 where GroupID is the primary key and is an Identity column. How do you insert a new row into the table (and hence generate a new ID) without using IDENTITY_INSERT ON? N...

SQL Encode string parameter so special characters work

I would like to be able to add a new SQL LOGIN and name it after a person email address. For example "[email protected]". When I pass this to the following stored procedure I get an error (error follows procedure). The stored proc: CREATE PROCEDURE [Forms].[AddLogin] @Email nvarchar(2048), @TenantPassword nvarchar(2048) AS BEG...

What are the system tables used in Sql Server replication?

What are the system tables used in Sql Server replication? ...

sql_who2 gives -2 in the BlkBy column

We had a problem today on our dev server where a process locked one table, stopping all other queries on that table to work. When running sql_who2 the blkBy columns value was -2, but the -2 was not in the process list. When running DBCC INPUTBUFFER (-2) I got the exception Invalid SPID -2 specified. When running beta_lockinfo I see all...

What are the magic tables available in SQL Server 2000?

What are the magic tables available in SQL Server 2000? I wonder, why they are 'magic' tables? ...

What is the use of maintance plans in SQLSERVER2005

Can anyone tell me what is the need and use of sqlserver maintanance plans and how to configure them. ...

Min effective and termdate for contiguous dates

Hi, Is there w way to achieve following using an SQL 2000 query, i looked everywhere but could not find any working snippet. I have contiguous date segments and requirement is to get the min effective date and maximum effective dates for each contiguous dates. if that is not possible getting min effective date and max termdate for an ...