sql-server

How am I misunderstanding trigger recursion in TSQL?

I have the following table: if object_id(N'dbo.Node') is null create table dbo.Node ( ID bigint identity primary key, ParentID bigint null, -- references Node(ID) DateCreated datetime not null, LastUpdated datetime not null, [Name] nvarchar(500) not null, ); I have this trigger to achieve cascading deletes within t...

Using CLR to get value from registry

Is there a way to get a value from the registry using a CLR procedure that doesnt involve having to registry Microsoft.Win32 as an assembly in SQL Server? I am looking to get the DigitalProductId (I will need to decode it to a string) from the registry within a CLR proc and return it to SQL. Supported Namespaces CustomMarshalers Micro...

Sql Server 2005 Fulltext case sensitivity problem

I seem to have a weird bug in Microsoft SQL Server 2005 where FREETEXT() searches are somewhat case-sensitive despite the collation being case-insensitive (Latin1_General_CI_AS). First of, LIKE queries are perfectly case-insensitive, so WHERE column LIKE '%word%' and WHERE column LIKE '%Word%' return the same results. Also, FREE...

What is the most interesting SQL Question(TSQL Program included) that you encountered?

Actually I am a newbie in SQL SERVER (only 2 months as of now) and want to learn more and master it over the coming days. So I have asked this question. I believe it will help people like me a lot to grow if we follow those that the experienced peoples here have faced or seen so far in their career. Also it will help us in our job or ...

Is there a way in SQL Server Management Studio to view field data in a multi-line editable field?

I have a database that I am viewing with SQL Server Management Studio 2008. I right-click on the table and choose edit top 200 rows. I tab over to my "SerializedXML" varchar(max) field that has 100s of lines of data in it but I am only able to move back and forth in it with my cursor in a tiny one-line textbox. I remember there being ...

Fastest way to change column data type in SQL Server

In SQL Server 2008, I have got a table of around 3 million records. I want to change the type of one of its columns from float to int. But seems it will take a lot of time. Is there any way to accomplish this very fast? ...

SQL Server Rounding Issue Looking for Explanation

Hi Everyone, I've solved this issue but I'm just wondering why this works the way it does. I have a temporary table I am selecting from and am looking to display a a name, the number of records that match this name, and the percentage for that name of the total records. This is the way I originally had it: SELECT name, number, CASE...

Speeding up database access

I have a database containing records collected every 0.1 seconds, and I need to time-average the data from a given day to once every 20 minutes. So I need to return a day's worth of data averaged to every 20 minutes which is 24*3 values. Currently I do a separate AVG call to the database for each 20-minute period within the day, which i...

Versioning SQL Server DDL code

I'd like to have all DB DDL code under CVS. We are using Subversion for our .NET code. But all Database code remains still unversioned. All we know how important DB logic can be. I've googled but I've found only few (expensive tools) I believe there exist other (cheaper) solution(s) I'm wonder your approach. How do you implemente...

UI for SQL Server User managment

B"H I am building a solution for a small business without any in house IT staff. The central datastore is SQL SERVER (express2008) I would like to leverage SQLs built in security (certain views for certain classes of employees). However the boss (the one who needs the control to say who sees what and who can edit) is overwhelmed by M...

Marking persisted computed columns NOT NULL in SQL Server Management Studio

It is possible in SQL Server 2005 to create a computed column that is both persisted and is defined as NOT NULL (cannot contain a null value). The 2nd attribute is of importance when using libraries like Linq2Sql if we want to avoid a lot of manual work to assure our code that the column 'always' has a value. With straight SQL this is v...

SQL Server: Create Table using first row of Text File as Column names

Hello all, How can I read the first row of a text file (comma separated) and use that as the field names of a new table I want to create in SQL Server? The field names can all be varchar. Thanks all UPDTAE Please note I would like to do this using T-SQL or any other way (sqlcmd etc). I do not want to use the wizard. ...

How do I query schema bound views?

I can list all views in SQL Server 2008 by using 'SELECT * FROM sys.views' What I want to do is list only the views that are schema bound. How can I do this? ...

How to fix Distributed Transaction Manager (MSDTC) has been disabled errors

We are using transaction scope features of ASP.NET to manage distributed transaction for that we need to enable distributed transaction via following link: The partner transaction manager has disabled its support for remote/network transactions Its works well with SQL Server 2005 and Windows Server 2003 but when it comes to Windows Serv...

Sharing transactional space between two connections

There's an app that starts a transaction on SQL Server 2008 and moves some data around. Then, while the transaction is still not committed, the app prints out some labels. It is very important that the transaction is not committed until printing succeeded; if a printing error occurs, everything is rolled back. Now, the printing engine i...

Database Objects Scripts in Order???

When we script all Sql Server Database objects from Management Studio by right clicking on the database, and go to tasks and select "generate scripts", will the generated scripts be in order??? ...

After insert trigger question - SQL 2008

I have data coming in from datastage that is being put in our SQL Server 2008 database in a table: stg_table_outside_data. The ourside source is putting the data into that table every morning. I want to move the data from stg_table_outside_data to table_outside_data where I keep multiple days worth of data. I created a stored procedu...

Using a duplicate SQL Server database for queries

I have a very large (100+ gigs) SQL Server 2005 database that receives a large number of inserts and updates, with less frequent selects. The selects require a lot of indexes to keep them functioning well, but it appears the number of indexes is effecting the efficiency of the inserts and updates. Question: Is there a method for keeping...

SQL Server - Stored Procedure Question

For the application I work on... we're creating a custom logging system. The user can view logs and apply "Tags" to them (Just like how you can apply tags to questions here!) In this example, I'm trying to get a list of all the Logs given a "Tag." I realize I can accomplish this by using joins... but this is also an exercise for me to l...

Return all xml nodes import into SQL Server

I have imported an xml document into SQL Server, I am now trying to import various parts into different tables. When I use the below query it only returns one row of hotel_facilities, I need to return all the hotel_facilities with the hotel_ref. DECLARE @Details xml SET @Details = '<hotels> <hotel> <hotel_ref>105</hotel_ref> <...