sql-server

How do to massively alter primary keys to tables in sql server database

Hi Is there any way to massively alter primary keys(uid) to all tables with no primary keys in sql server database ? I have a lot of tables and most of them don not have primary keys. Thanks in advance. ...

How can I change the look of SQL Server Managment Studio based on which database I'm connected to?

I'd like to modify the appearance of the query window in SQL Server Management Studio based on which database I'm currently connected to. For example, using a yellow background for production databases. Is there a way to do this? UPDATE: Is there also a way to change the default color of the query status bar at the bottom (when a serv...

How to export a database from SQL server 2008 to SQL server 2005

I have a database which I made using SQL server 2008. I have to attach this database into SQL server 2005. When I try to do so , I got an error since the database is made in higher version (2008). How can I do so? Any help ? ...

slow SQL command

I need to take some data from one table (and expand some XML on the way) and put it in another table. As the source table can have thousands or records which caused a timeout I decided to do it in batches of 100 records. The code is run on a schedule so doing it in batches works ok for the customer. If I have say 200 records in the sourc...

Saving russian text in SQL server

Hi, I have a database (SQL server express 2008) which has a column that is defined as text. When we try to store some text which is in chinese, it is not saved. I read that the field should be ntext. I will now have to a conversion to my table to create the column as ntext. Would I have to do anything with the collation of the database...

Microsoft SQL Server 2005 Function, passing list of start and end times

I'd like to do had a dynamic number of one start/end time pairs passed to a function as an input parameter. The function would then use the list instead of just one start, and one end time in a select statement. CREATE FUNCTION [dbo].[GetData] ( @StartTime datetime, @EndTime datetime ) RETURNS int AS BEGIN SELECT @EndTime =...

What is the best way to truncate a date in SQL Server?

If I have a date value like 2010-03-01 17:34:12.018 What is the most efficient way to turn this into 2010-03-01 00:00:00.000? As a secondary question, what is the best way to emulate Oracle's TRUNC function, which will allow you to truncate at Year, Quarter, Month, Week, Day, Hour, Minute, and Second boundaries? ...

SQL Server and distributed databases. How synchronize?

Hello everyone, I'm planning a project for managing multiple distributed databases and I am raising the question of how to efficiently synchronize the data. The project will be developed with technology. NET and SQL Server. There will be a local database in which the company will load data, some of these data (not all) should be synchr...

Cannot use READPAST in snapshot isolation mode

I have a process which is called from multiple threads which does the following: Start transaction Select unit of work from work table with by finding the next row where IsProcessed=0 with hints (UPDLOCK, HOLDLOCK, READPAST) Process the unit of work (C# and SQL stored procedures) Commit the transaction The idea of this is that a thre...

How to save an order (permutation) in an sql db

I have a tree structure in an sql table like so: CREATE TABLE containers ( container_id serial NOT NULL PRIMARY KEY, parent integer REFERENCES containers (container_id)) Now i want to define an ordering between nodes with the same parent. I Have thought of adding a node_index column, to ORDER BY, but that seem suboptimal, since that...

sql server - Sum() column X, but add column Y only once

My table is like this A | X | Y --+---+-- 1 | 2 | 3 1 | 4 | 3 2 | 9 | 1 2 | 7 | 1 What I want is to sum X column with Group By A but add Y only once. The values in column Y are always same for a specific A. When I run this: SELECT SUM(X + Y) FROM TABLE GROUP BY A It gives me: 12, 18. But I need 9, 17. Thanks. ...

Pdssql.dll cannot be found

I am attempting to open a Crystal Reports 8.5 document, and when I try to set the database to the Production data server, i get the error "Pdssql.dll cannot be found". Googling, this is a common problem, but none of the fixes I tried seem to work. This is a new computer. I do have SQL Server 2008 client tools installed, but I believe ...

SQL: how to get the left 3 numbers from an int

I want to retrieve the left 3 numbers from an integer to be stored in a table. For example, if the int is 1234567, I want to retrieve 123. I want the second number (123) to also be an int; I don't want to convert anything to a string. (And yes, really I should be working with strings. But I don't have control over that aspect of the iss...

Sql server query using function and view is slower

I have a table with a xml column named Data: CREATE TABLE [dbo].[Users]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName] [nvarchar](max) NOT NULL, [LastName] [nvarchar](max) NOT NULL, [Email] [nvarchar](250) NOT NULL, [Password] [nvarchar](max) NULL, [UserName] [nvarchar](250) NOT NULL, [LanguageId] [int] ...

Micosoft SQL Server 2005 check if temporary table empty

Is there a fast/efficiency way to check if a table is empty? DECLARE @StartEndTimes TABLE ( id bigint, StartTime datetime, EndTime datetime ) IF @StartEndTimes IS NOT NULL ...

Microsoft SQL Server 2005 Console Write Line

Is there a way to write a message to the console? I'd like to write some debug data if it's possible. ...

SQL datasource for gridview

Hi I want to use a gridview with sorting and paging to display data from an SQL server, the query uses 3 joins and the full text search containstable. The from part of the query uses all 3 tables in the join. What is the best way to do this? I can think of a stored procedure, SQL directly in the SQLDataSource and creating a view in the...

SSIS Permissions issue

Hi All, How can we set permissions for users to only allow them to download SSIS packages from the production server and but deny them permissions to run any package in the Server. http://msdn.microsoft.com/en-us/library/ms141053(SQL.90).aspx If i assign users to any of the DB roles db_dtsadmin, db_dtsltduser, and db_dtsoperator they...

Microsoft SQL Server 2005 cast bigint to string

How can I cast a bigint variable to a string? DECLARE @id bigint ...

Microsoft SQL Server 2005 cast date/time to string

How can I convert @lastEndTime to a string formated YYYY-MM-DD HH:MM:SS.MS? DECLARE @lastEndTime datetime ...