sql-server

Getting autonumber primary key from MS SQL Server

I am currently working in C#, and I need to insert a new record into one table, get the new primary key value, and then use that as a foreign key reference in inserting several more records. The Database is MS SQL Server 2003. All help is appreciated! ...

SQL Server 2005 database stuck in single user mode

I have a database that is stuck in single-user mode. I kill the process that obtains the "lock" on the db but when I kill it another one spawns automatically, (using the sa account). This happens even with SQL Server agent disabled. Any ideas? ...

How does DB2 Express compare to Sql Server Express?

I have only just found out about DB2 Express. I had a quick look and was unable to find a load of information about it but would be interested in hearing how people have found it compared to SQL Server Express (particularly 2008) in terms of Ease of deployment Ease of use and development tools Limitations such as size or CPU limits...

Clever tricks to find specific LINQ queries in SQL Profiler

Profiling LINQ queries and their execution plans is especially important due to the crazy SQL that can sometimes be created. I often find that I need to track a specific query and have a hard time finding in query analyzer. I often do this on a database which has a lot of running transactions (sometimes production server) - so just ope...

Can SQL Server Express be used to effectively administrate a SQL Server Standard/Enterprise installation?

We have a number of MS SQL Server 2005 installations (both Standard and Enterprise editions) on our webservers. From time to time I need to administrate them from home. Right now I'm using Remote Desktop to connect to my work machine, but I'd prefer to install SQL Server Management Studio on my home machine so that I can work more effici...

Determining database from which function in separate utility database is being called

I have several databases, one of which contains utility functions called from the other databases. Is there a way in the utility functions to determine which database a function is being called from? ...

rename schema in SQL server 2005

How can I rename a schema in SQL Server 2005? ...

Table and Index size in SQL Server

Can we have a SQL query which will basically help in viewing table and index sizes in SQl Server. How SQL server maintains memory usage for tables/indexes? ...

Is it possible to use CONTAINSTABLE to search for "word1" in column1 AND "word2" in column2

We used to have a search, that checks two columns for some words. Both columns must contain some words provided, so we use AND ... no doubts FULLTEXT INDEX is used on the columns. The select is more or less like this: SELECT * FROM SomeTable WHERE (CONTAINS(Column1, 'word1 OR word2') AND CONTAINS(Column2, 'word3 OR word4')) now ...

Efficient Way To Query Nested Data

I have need to select a number of 'master' rows from a table, also returning for each result a number of detail rows from another table. What is a good way of achieving this without multiple queries (one for the master rows and one per result to get the detail rows). For example, with a database structure like below: MasterTable: -...

Paste MS Excel data to SQL Server

I have a bunch of rows in Excel that I want to paste into a new table in MS SQL. Is there a simple way ? ...

Query to get time consuming sql statements in SQL Server

How can we get information regarding poorly performing sqls(taking too much time for execution) Does MS SQL server maintains tables/views (Similar to v$sql in Oracle) for storing sql queries. ...

Optimized SQL for tree structures

How would you get tree-structured data from a database with the best performance? For example, say you have a folder-hierarchy in a database. Where the folder-database-row has ID, Name and ParentID columns. Would you use a special algorithm to get all the data at once, minimizing the amount of database-calls and process it in code? Or ...

SQL if statement in where clause for searching database

I'm creating a stored procedure to return search results where some of the parameters are optional. I want an "if statement" in my where clause but can't get it working. The where clause should filter by only the non-null parameters. Here's the sp ALTER PROCEDURE spVillaGet -- Add the parameters for the stored procedure here @accomod...

Is a dynamic sql stored procedure a bad thing for lots of records?

Hello, I have a table with almost 800,000 records and I am currently using dynamic sql to generate the query on the back end. The front end is a search page which takes about 20 parameters and depending on if a parameter was chosen, it adds an " AND ..." to the base query. I'm curious as to if dynamic sql is the right way to go ( does...

SQL Server Hash Indexes

When using the CHECKSUM column type to artificially create a hash index, is the lookup actually O(1) or is it still O(lg n) like it is for a clustered index? I have a table from which I will select based on its ID column and I need the lookup to be as fast as possible, so is the clustered index the fastest possible option? I am looking f...

SQL Conditional Order By

I am doing a join on two tables. One is a user's table, and the other a list of premium users. I need to have the premium members show up first in my query. However, just because they are in the premium user table doesn't mean they are still a premium member - there is an IsActive field that also needs to be checked. So basically I need...

SQL Server - update one table with first and last rows from another table.

I have a couple of tables which are used to log user activity for an application. The tables looks something like this (pseudo code from memory, may not be syntactically correct): create table activity ( sessionid uniqueidentifier not null, created smalldatetime not null default getutcdate() ); create table activity_details ( ses...

Database files and ASP.NET Login controls.

I was trying the ASP.NET login control tutorial and everything works well. However, I do not know how to have the Log-in control use my own database (SQL Server 2005) instead of using it's mdf file. I also have no idea where this file was created from since it doesn't show up at all on my solution. Any literature that I can find on the w...

What is the best practice for handling null int/char from a SQL Database?

I have a database that hold's a user's optional profile. In the profile I have strings, char (for M or F) and ints. I ran into an issue where I try to put the sex of the user into the property of my Profile object, and the application crashes because it doesn't know how to handle a returned null value. I've tried casting the data to th...