sql-server

Why is doing a top(1) on an indexed column in SQL Server slow?

I'm puzzled by the following. I have a DB with around 10 million rows, and (among other indices) on 1 column (campaignid_int) is an index. Now I have 700k rows where the campaignid is indeed 3835 For all these rows, the connectionid is the same. I just want to find out this connectionid. use messaging_db; SELECT TOP (1) connect...

Possible to compress SQL Server network traffic?

I have a .NET client that needs to connect to a remote SQL Server over the WAN, is it possible to compress SQL traffic between the client and the server? I am using .NET 3.5 and SQL Server 2005 and greater. ...

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.

I get "The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified." error with the following code. I initially had two tables, ADSAREAS & CATEGORIES. I started receiving this error when I removed CATEGORIES table. Select Case SIDX ...

Advice on setting up a central db with master tables for web apps

I'm starting to write more and more web applications for work. Many of these web applications need to store the same types of data, such as location. I've been thinking that it may be better to create a central db and store these "master" tables there and have each applicaiton access them. I'm not sure how to go about this. Should I ...

SQL Server 2005 Issue Column name or number of supplied values does not match table definition.

Hello, I wish to DELETE the data from a table before performing an INSERT INTO, however I keep recieving an error stating: Insert Error: Column name or number of supplied values does not match table definition. I've also tried defining the columns the data should be entered into as part of the INSERT INTO statement, but then get issu...

Date ranges intersections..

MS Sql 2008: I have 3 tables: meters, transformers (Ti) and voltage transformers (Tu) ParentId MeterId BegDate EndDate 10 100 '20050101' '20060101' ParentId TiId BegDate EndDate 10 210 '20050201' '20050501' 10 220 '20050801' '20051001' ParentId TuId BegDate EndDat...

Is is faster to filter and get data or filter then get data ?

Hi I have this kind of request : SELECT myTable.ID, myTable.Adress, -- 20 more columns of all kind of type FROM myTable WHERE EXISTS(SELECT * FROM myLink WHERE myLink.FID = myTable.ID and myLink.FID2 = 666) myLink has a lot of rows. Do you think it's faster to do like this : INSERT INTO @result(ID) SELECT myLink.FID FROM...

Refreshing metadata on user functions t-SQL

I am doing some T-SQL programming and I have some Views defines on my database. The data model is still changing these days and I have some table functions defined. Sometimes i deliberately use select * from MYVIEW in such a table function to return all columns. If the view changes (or table) the function crashes and I need to recomp...

Accepted date format changed overnight

Since yesterday I started encountering errors related to date formats in SQL Server 2008. Up until yesterday the following used to work. EXEC MyStoredProc '2010-03-15 00:00:00.000' Since yesterday I started getting out of range errors. After investigating I discovered the date as above is now being interpreted as "the 3rd of the 1...

View temporary table`s data when debugging an MS SQL Function

I'm currently debugging an Ms SQL Function (SQL 2008). In this function, I have a variable declared this way: DECLARE @TempTable TABLE ( Id INT UNIQUE ); Then, I insert some records using an insert into...select statement. When debugging, I would like to see the records in this table. Is there a way to do this? Thanks ...

Using SQL Server for WSS 3.0 instead of Windows Internal database

Hi Folks, There are actually two related questions: is it possible or advisable to use a full blown stand-alone SQL server for SharePoint Services WSS3.0 instead of the supplied windows internal database it comes with? The client I am working for is asking to utilize their existent SQL server for all WSS content databases to possibly...

SQL server management studio Express

I authenicate to my SQL Server instance by logging in with a Windows account via SQL Server Management Studio. I want to change this to a SQL server login. How can I do that? ...

SSMS 2008 Add-In - Execute Query

I'm loading a sql script up to an SSMS 2008 add-in like so: ' create a new blank document ServiceCache.ScriptFactory.CreateNewBlankScript(Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptType.Sql) ' insert SQL statement to the blank document Dim doc As EnvDTE.TextDocument = CType(Service...

Using a combo box in access to list all the available sql servers and connected databases

Is there a way I can set up combo box in an access form to list all the available sql servers and then an associated combo box to list the related databases? Can this be done in access? ...

Passing Binary Data to a Stored Procedure in SQL Server 2008

I'm trying to figure out a way to store files in a database. I know it's recommended to store files on the file system rather than the database, but the job I'm working on would highly prefer using the database to store these images (files). There are also some constraints. I'm not an admin user, and I have to make stored procedures to ...

Replace duplicate spaces with single space in TSQL

I need to ensure that a given field does not have more than one space (not concerned about all white space, just space) between characters. So 'single spaces only' Needs to turn into 'single spaces only' The below will not work select replace('single spaces only',' ',' ') as it would result in 'single spaces onl...

Why won't this SQL CAST work?

I have a nvarchar(50) column in a SQL Server 2000 table defined as follows: TaskID nvarchar(50) NULL I need to populate this column with random SQL GUID's using the NEWID() function (I am unable to change the column type to uniqueidentifier). I tried this: UPDATE TaskData SET TaskID = CAST(NEWID() AS nvarchar) but I got the follow...

How to organize infinite while loop in SQL Server ?

I want to use infinite WHILE loop in SQL Server 2005 and use BREAK keyword to exit from it on certain condition. while true does not work, so I have to use while 1=1. Is there a better way to organize infinite loop ? I know that I can use goto, but while 1=1 begin .. end looks better structurally. ...

how Do I list all table names in SQL Server using T-SQL?

SELECT name FROM sys.databases -- this can list all database name in the server user database SELECT * FROM INFORMATION_SCHEMA.TABLES -- these two line can list the table for one particular database But how can I output the results like below? Database Table --------- ------------- db1 ...

How to properly name record creation(insertion) datetime field ?

If I create a table with datetime default getdate() field that is intended to keep date&time of record insertion, which name is better to use for that field ? I like to use Created and I've seen people use DateCreated or CreateDate. Other possible candidates that I can think of are: CreatedDate, CreateTime, TimeCreated, CreateDateTime,...