sql-server

Building an automated script based Backup / Maintenance Solution

Guys, My company at present has the following Setup: 127 SQL servers (2000 and 2005) and over 700 databases. We are in the process of server consolidation and are planning on having a Master server / Target servers setup to enable centralized administration. As part of this project, I have been given the responsiblity of creating a scr...

SQL Server 2000 - My query is running slowly, all of sudden

My database query has been running very fast until it changed to very slow recently. No changed have occurred in the database apart from normal data growth. I have noticed that the database statistics have "never" been updated. Is there an easy way that I can update these statistics across my entire database so I can see if that is t...

Find index of last occurrence of a sub-string using T-SQL

Is there a straightforward way of finding the index of the last occurrence of a string using SQL? I am using SQL Server 2000 right now. I basically need the functionality that the .NET "System.String.LastIndexOf" method provides. A little googling revealed this - http://www.sqlservercentral.com/scripts/T-SQL+Aids/31116/ - but that doe...

Find an object in SQL Server (cross-database)

If I've been told a table (or proc) name, but not which connected database the object is located in, is there any simple script to search for it? Maybe search somewhere in the System Databases? (I'm using SQL Server 2005) ...

Calculate missing date ranges and overlapping date ranges between two dates

I have the following set of dates (dd/MM/yyyy) matching events in my database: eventId startDate endDate 1 02/05/2009 10/05/2009 2 08/05/2009 12/05/2009 3 10/05/2009 12/05/2009 4 21/05/2009 21/05/2009 5 25/05/2009 NULL 6 01/06/2009 03/06/2009 The ev...

sql server clustered index on a view

hey everyone, Im trying to create a view out of quite a complex select query and it wont let me put a clustered index on it because i have to use subqueries and some aggregate functions. I have to get a clustered index on it otherwise the queries that use the view will take forever. Apparently sql server will only store the result set ...

How to get number of chars in string in Transact SQL, the "other way"

Hi, we faced very strange issue (really strange for such mature product): how to get number of characters in unicode string using Transact-SQL statements. The key problem of this issue that the len() TSQL function returns number of chars, excluding trailing blanks. the other variant is to use datalength (which return number of bytes) and...

How do I specify a column to be unique in the scope of a relationship in SQL Server 2008?

It's easier with an example. I have two tables: Books and Chapters. Both have Title and Id columns. Chapters also has a Book column which is a foreign key to Books.Id. Books.Title is unique (I don't want two books with the same title). Now my problem is defining Chapter.Title uniqueness. I want it to be unique as long as Books.Id is the...

How to Create a Table from the recordset value

How to Create a Table from the recordset value sqlCardEvent1 = "select * from tmp_CARDEVENT" If rsCardEvent1.State = 1 Then rsCardEvent1.Close rsCardEvent1.Open sqlCardEvent1, Cn, adOpenStatic, adLockOptimistic cmdCardEvent1.CommandText = sqlCardEvent1 Set rsCardEvent1 = cmdCardEvent1.Execute sql33 = "create table t...

Limited T-SQL Join

This should be simple enough, but somehow my brain stopped working. I have two related tables: Table 1: ID (PK), Value1 Table 2: BatchID, Table1ID (FK to Table 1 ID), Value2 Example data: Table 1: ID Value1 1 A 2 B Table 2: BatchID Table1ID Value2 1 1 100 2 1 101 3 1 102 1 ...

How to display a today date column, time column, previous date column, time column

Using Access Database Table Cardno name cardeventdate Intime Outtime 0001 Michael 20080811 102746 185249 0001 Michael 20080812 080828 080828 0002 Michael 20080811 082615 082615 0002 Michael 20080812 073624 190605 From the Above Table I want to Display another Two Column like C...

How to find what sql process caused a delete in SQL 2000?

I've seen queries for 2005/2008 to find what process caused a delete but have not seen anything for 2000. Is there anything? ...

Can I use .mdf file (sql 2005 express) on machine without sql express installation

Hi Expert, Is it possible that, I can use sql express .mdf file in our desktop project and deploy it on client's machine without sql express installation ? If so please provide me the steps and connectionstring. Thanks in advance. Anil ...

PHP + SQL Server or VB.NET + MySQL

Can someone suggest that out of the two mentioned (odd?) combinations, which is less odd, or in other words, is less trouble to work with + maintain. If it helps, the system is going to have two front-ends - one web application and one desktop application. The desktop application is going to be coded using VB.NET, and the web applicatio...

Is there any way to DISTINCT or group by a text (or ntext) in SQL Server 2005?

In a table, I have a column called MEMO_TEXT that is a text data type. When I try creating a view and use a GROUP BY, I get the following error: SQL Server Database Error: The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. I get this error when I try to do a DISTINCT on the ...

Column (Cost) was used in a CALC expression but is not defined in the rowset.

Keep getting this error after inserting a subdatasheet into a query and trying to show it by clicking on the + Column (Cost) was used in a CALC expression but is not defined in the rowset. What is confusing, is that there isn't even a column named 'Cost' anywhere in the database. Although there is a column that starts with 'Cost' and ...

When does a database table get large enough that an index is beneficial?

Hypothetically, in a SQL Server database, if I have a table with two int fields (say a many-to-many relation) that participates in joins between two other tables, at what approximate size does the table become large enough where the performance benefit of indexes on the two int fields overcomes the overhead imposed by said indexes? Are ...

Too many parameters were provided in this RPC request. The maximum is 2100. ?

A search query returned this error. I have a feeling its because the in clause is ginormous on a subordinant object, when I'm trying to ORM the other object. Apparently in clauses shouldn't be built 1 parameter at a time. Thanks ibatis. ...

Should I create a ADO.NET Entity Data Model for each table, or one for my entire database?

Hi, Are you supposed to use one ADO.NET Entity Data Model for each table? Or one for your entire database where relationships are also routed, etc... ...

Display DataType and Size of Column from SQL Server Query Results at Runtime

Is there a way to run a query and then have SQL Server management studio or sqlcmd or something simply display the datatype and size of each column as it was received. Seems like this information must be present for the transmission of the data to occur between the server and the client. It would be very helpful to me if it could be dis...