sql-server

SQL Server Connection and Vista 64 bit?

I just upgraded to Vista 64bit. I was running the 32bit version without any issues. For some reason my connection to my SQL server times out. If I go to the server, everything seems to be ok there. I have unlimited conenctions to it and I can connect locally via the Management console. I have a web app running .net 3.5. Is I use the clie...

SQL Server database backup plan and log truncation

I have a SQL Server 2005 database that is backed up nightly. There backup consists of: 1 FULL backup of the database. 1 backup of the transaction log. These are currently two separate jobs. The log is huge and I'd like to set things up so that: 1) the database is backed up in full nightly 2) the log is set such that I can recover the...

Using System Tables to Count the Percent of Rows Null in Various Tables

I'm trying to determine the percent of null items for all fields of a table. I have to run this on several tables with a ton of fields, and I was looking for an automated way of doing this. I know I can query "information_schema.columns" and get a nice clean list of field names ala: select Column_name from information_schema.columns ...

SQL Server: displaying first line of grouped records

Am trying to write a query that would output something similar to the last batch of records below. For sure it works in Reporting Services and Crystal Reports, but just throwing it out here to see if it is possible in SSMS/QA: Table: id name amount -- ---- ------ 1 rob 23.00 2 rob 34.00 3 dan 45.00 4 dan 56.00 select name...

Upload large amounts of data to production sql server with minimal contention

I am running a web site that helps manage lots of information for medical clinics. Part of the application needs to upload patient files from an excel spreadsheet. The patient table has about 1 million records and an excel import needs to insert or update 10k,20k,30k patient records at a time. All the while other customers are poundin...

Tools to help me generate an xml schema for a mssql database?

I'd like to be able generate an xsd of my MSSQL database's structure. Are there any tools or libraries that help me to this? The VS designer for typed datasets come's close, but I'm looking for a programmatic approach. ...

best way to keep track of an ordered smalldatetime column

I know the difference between smallDateTime and timeStamp. Right now I am using smallDateTime because the precision is good enough for my needs. But the problem is that I still need to keep inserted items in order and smallDateTime is mixing things up if the inserts come too close to each other. Is it an acceptable practice to use both ...

Temporary function or stored procedure in T-SQL

Hello is there any chance to create temporary stored procedure or function on MS SQL 2005? I would like to use this stored procedure only in my query so after execution it will be gone. I have a query I would like to EXEC against some data. But for every table I will process this command I need to change some parts of it. So i thought I...

Differentiate empty from NULL query results

I've got a table with measurement data in SQL Server 2005, one value per person and year, if available. My TSQL code fetches these values in a loop and processes them: ... SET @val = (SELECT measurement FROM tbl_data WHERE persid = @curpersid AND yr = @curyear) ... Now, for a certain person and year, the table can contain (i) a valid ...

Turn off constraints temporarily

I'm looking the way to temporarily turn off all DB's constraints (eg table relationships) I need to copy (using INSERTs) one DBs tables to another DB I know I can archive that by executing commands in proper order (to do not break relationships) But it would be easier if I could turn off checking constraints temporarily and turn on it...

How to disable primary key constraint programmatically?

I have a table with primary key in my MS SQL Server 2005 table. I would like to disable it. Now i get error: Violation of PRIMARY KEY constraint 'PK_Name'. Cannot insert duplicate key in object 'dbo.Table'. I would like this error not to occur and to work with PRIMARY KEY like with normal column without constraint and than restore this...

Is there an easy way to give an option to open Excel on export form SSRS reportviewer control?

If we export to Excel from the ReportingServices reports web site, the user gets an option to Open/Save/Cancel. However, the reportviewer control for winforms does not give the Open option. The user has to save the file and then open it manually. I'm wondering if someone else has already crossed this bridge and might be able to save me...

How to control order of Update query execution?

I have a table in MS SQL 2005. And would like to do: update Table set ID = ID + 1 where ID > 5 And the problem is that ID is primary key and when I do this I have an error, because when this query comes to row with ID 8 it tries to change the value to 9, but there is old row in this table with value 9 and there is constraint violation...

SQLSERVER Management Objects in c++ Programming

How to use SQLSERVER SMO in C++(CPP) to list all the servers availabel and find databases installed using VS2003/VS2005 IDE. And i need some clarification in 1)Does Vs2003 Have support for SQLSMO?? 2)Is any additional files(reference) needed to work with SMO in VS2003? if yes what r those? Thanks in Advance... ...

varchar(max) MS SQL Server 2000, problems?

Hi, I've inherited a asp.net website project that currently runs MS SQL 2000 as its backend. I've been doing some databases changes on a local copy of the db using MS SQL Server 2005 Express. I've create a table using varchar(max) columns. They are used to stored snippets of XHTML that are of arbitrary length. While browsing around on ...

How do you count the number of occurrences of a certain substring in a SQL varchar?

I have a column that has values formatted like a,b,c,d. Is there a way to count the number of commas in that value in T-SQL? ...

SQL Server Subscription Initialization Restarts Endlessly, Never Finishes

I'm trying to set up transactional pull replication on 2 SQL Server 2005 instances, through a 3rd as a distributor. When the subscription is being initialized, it bulk inserts properly, giving the message that the snapshot was successfully loaded. Then it makes primary key indexes as usual. At this point the job starts over, dropping al...

Tools to Replay Load on a SQL Server

Has anyone come across any good tools (preferably but not necessarily FOSS) that can read a SQL Server (2005/2008) trace file and execute the commands against another database. We are attempting to perform some performance testing on our SQL servers and would like to replicate an actual load. I have come across but not yet used: JMet...

SQL Server index question - address lookup

I have a table which may have anywhere from 10,000 to 10 million rows during the life of the application. This table contains NACSZ info, among other things, and I need to write a query that checks for matching NACSZ like so: select * from Profiles where FirstName = 'chris' and LastName = 'test' and Address1 = '...

Add row to query result using select

Hey guys, is it possible to extend query results with literals like this? Select name from users union select name from ('JASON'); or Select age, name from users union select age, name from (25,'Betty'); so it returns all the names in the table plus 'JASON', or (25,'Betty'). Thanks! ...