sql-server

How do I query a SQL database for a lot of results that don't have any common criteria?

I have a MS SQL DB with about 2,600 records (each one information on a computer.) I need to write a SELECT statement that selects about 400 of those records. What's the best way to do that when they don't have any common criteria? They're all just different random numbers so I can't use wildcards or anything like that. Will I just hav...

How can I drop all the default constraints constraints on a table

Hi All, How can I drop all the default constraints belonging to a particular table in SQL 2005? ...

SQL Server 2005 Replication, transactional with updateable subscription error

Several days ago i setup some replication for our SQL Server 2005 database, the type of replication was a transactional with updateable subscription. The replication are working fine, lately i test the upgradeable subscription feature by modifying 1 data on subscriber server but then the error was raise and data are not committed. The ...

How do I create unique constraint that also allows nulls in sql server

The question is quite simple, as the title. Added a column to table I want a unique constraint , the column will insert guids, but to allow for existing data before column was added I need to allow for nulls in the check ...

total pages in a report using report viewer

i want to get total number of pages in form,which is placed report viewer..(int t=int T = objReportViewer.LocalReport.GetTotalPages();)i used this code,actually report have 5 pages but got only one page ...

Difference between sp_spaceused and DataLength SQL Server

I have a table with single Row when i use SP_SpaceUsed N'<TableName>' it gives me data as 16 KB and when I use dataLength something like this:- select ClientID , (0 + isnull(datalength(ClientID), 1) + isnull(datalength(LeadID), 1) + isnull(datalength(Company_Name), 1) + isnull(datalength(Website), 1) + isnull(datalength(EmployeeC...

Can I sync mobile, desktop and web server databases with Sync Framework?

I'm using Sync Framework v1 (which includes Sync Services for ADO.NET v2) and Sync Services for mobile v1. I can sync a SQL Compact Edition database from a mobile device to SQL Express on a desktop PC. I can also sync a SQL CE database from a desktop PC to a SQL Server database on a web server using WCF. I want to sync from the mobil...

Export hierarchical data into XML

Our database contains hierarchical "items". Every item has detail information inside a separate table. E.g. an item could be a folder or a file. Now I would like to export children of an item to XML. For performance reasons I would like to do this inside a SP. Of course, it's possible to write a cursor-based SP, but cursors tend to be sl...

Is LTRIM(RTRIM(COALESCE(TextField,''))) Bad?

I have a very high-traffic table with a char(50) field which takes part in several indexes. This char(50) field allows NULLS, and in that case a NULL value is considered to be the same as a non-NULL, zero-length string for my purposes. I also disregard leading & trailing whitespace and, while I scrub the data before I insert it, it may...

Storing Files in a different Database?

Is it a good idea to store files in a different SQL Server 2005 database "FileDb" and point to it (files) in the "AppDb" by "FileId". Please take in consideration that I have a dedicated server and I can create as many Sql Databases as I want. update: Which perform better single database or multiple databsae? ...

How can I use the SqlFunctionAttribute in a database project to generate the SQL to deploy the functions myself? Visual studio fails.

Background: Visual studio fails at deploying a database project. It tries to drop functions that are already referenced (e.g. in a check constraint), rather than just adding the new ones and updating the existing ones, so the deployment always fails. As a result, I'm writing my own code to update the assembly and add/update any functi...

Is there a way to reset the IDENTIY column in sql server? and would this be a reason not to use an Identity Column?

I have a development database that has fees in it. It has a feeid, which is a unique key that is the identifier. The problem I run into is that the feeid/fee amount may not match when putting updating the table on a production server. This obviously could lead to some bad things happening, like overcharging for something or undercharg...

How do I insert a SQL Server result multiple times in a live word document using VB

Ok, I'm stuck trying to figure out how to take a mail merge, use that info to make MS SQL calls and get strings back in a word document. I'm guessing VB but I have no VB experience. ...

HOW TO: Umbraco 4.0 with Microsoft SQL Server 2000

We have a server that is running Microsoft SQL Server 2000 and would like to setup Umbraco 4.0. I tried the web install, but it choked on the MS SQL 2005 Express install. So I next tried the manual installation of MS SQL 2005 Express, which choked also with an error indicating that there was incompatibility issue because we already have ...

How do I change the owner of a SQL Server database?

When I accidentally click on the Database Diagrams tab, I get one of the following errors: Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the data...

Transaction count after EXECUTE error

I have a stored procedure that looks something like: CREATE PROCEDURE my_procedure @val_1 INT, @val_2 INT AS SET NOCOUNT ON; SET XACT_ABORT ON; BEGIN TRY BEGIN TRANSACTION; INSERT INTO table_1(col_1, col_2) VALUES (@val_1, @val_2); COMMIT TRANSACTION; END TRY BEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; ...

How can I remove the dbo prefix from my table names when I write my sql statements in SQL Server?

All the tables in my schema have a prefix of dbo. Now in my sql statements, I don't like using dbo.tablename all the time. Any workarounds or configuration changes? ...

Add a new table column to specific ordinal position

Is it possible to add a column to a table at a specific ordinal position in SQL Server? For instance, our tables always have CreatedOn, CreatedBy, LastModifiedOn, LastModifiedBy columns at the "end" of each table definition? I'd like the new column to show up in SSMS above these columns. If I am scripting all my database changes, is t...

How do I select a top level attribute of an xml column in SQL Server 2005?

I have an xml column in SQL Server 2005 that is the equivalent of: <Test foo="bar"> <Otherstuff baz="belch" /> </Test> I want to be able to get the value of the foo attribute of Test (the root element) as a varchar. My goal would be something along the lines of: select cast( '<Test foo="bar"><Otherstuff baz="belch" /></Test>' as xm...

Since SQL Server doesn't have packages, what do programmers do to get around it?

I have SQL SERVER database that have a huge proliferation of stored procedures. In my Oracle databases it's not a problem because Oracle supports packages. Even if SQL Server didn't support the cool features of packages like State and encapsulation, what do programmers do to get around this obvious deficiency? ...