sql-server

Refactoring ADO.NET - SqlTransaction vs. TransactionScope

I have "inherited" a little C# method that creates an ADO.NET SqlCommand object and loops over a list of items to be saved to the database (SQL Server 2005). Right now, the traditional SqlConnection/SqlCommand approach is used, and to make sure everything works, the two steps (delete old entries, then insert new ones) are wrapped into a...

Synchronize SQL Server over 'my own' comm. protocol

I am looking for a way to with little effort sync a master database (SQL Server) to several clients. A requirement in the project is to use a 'home made' communication protocol that already is in place for other software's. Basically the protocol can send/receive byte arrays to/from clients. I have been reading about Sync Services for ...

varchar or nvarchar

I am storing first name and last name with up to 30 characters each. Which is better varchar or nvarchar. I have read that nvarchar takes up twice as much space compared to varchar and that nvarchar is used for internationalization. So what do you suggest should I use: nvarchar or varchar ? Also please let me know about the performa...

Is it better to update or increment a value when persisting to a database?

I have an application where a user performs an action and receives points. Would it be a better idea to perform the arithmetic in the application and update the points database field with the resulting value, or have the database do the math? Assuming a user with 0 points is to receive 2 additional: //app does the math (0+2) and issues...

Why is there a difference in error handling clr procedures in sql server 2005?

I am using a clr procedure in one of my normal stored procs and i'm experiencing an odd error handling situation. Check the following code, it works as expected... BEGIN TRY create table #test(id varchar(2)) insert #test select '123' select * from #test END TRY BEGIN CATCH select 'an error occured but was handled' END CATCH Ho...

What accounts to use when installing SQL Server 2008 Developer

I am installing SQL Server 2008 Developer here, and on the Server Configuration step of the installation it asks me about Service Accounts. What do I choose here? I can see the available ones in the screen shot, although on most of them I can only select two or three of those. When I click the Use the same account for all SQL Server 200...

Create a folder in SQL Server 2008 like 'system databases'

In SQL Server 2008 Management Studio, how do I create a folder in my 'databases' folder similiar to 'system databases'. It would be a great way to group like db's. ...

Selecting overlapping time ranges

Hi - T-SQL DateTime Question. I have a set of time ranges. During those time ranges there could be a set of overlapping time ranges that I call 'blocked' out time. The blocked time wouldn't span more than one day. What I want to do is split the time to exclude the blocked out time, basically giving me the time ranges that are not 'block...

Subquery vs Traditional join with WHERE clause?

When joining to a subset of a table, any reason to prefer one of these formats over the other? Subquery version: SELECT ... FROM Customers AS c INNER JOIN (SELECT * FROM Classification WHERE CustomerType = 'Standard') AS cf ON c.TypeCode = cf.Code INNER JOIN SalesReps s ON cf.SalesRepID = s.SalesRepID vs the WHERE clause at the e...

Find the amount of missing attributes in an EVA design.... (remove the subquery from this sql join)

How would you remove the subquery within [Count of Missing Attributes] from the following example. --Setup data Declare @Attributes table (AttributeID int) Declare @Objects table (ObjectID int) Declare @ObjectAttributes table (ObjectID int, AttributeID int, val int) Insert Into @Objects (ObjectID) values (1) Ins...

Synchronizing SQL Data with or without a VPN

I have written a Windows application that stores data locally in a SQL Server Express database. It is used by multiple people from remote locations who need to synchronize their data occassionally. It requires a fairly simple synchronization process of only a handful of tables and I'm currently accomplishing this by linking each of the...

Understanding odd database key design

Background I'm having trouble understanding the primary key choices in the database for a major vendor supplied product that we support and write SQL reports on. Some irrelevant details have been changed. Each major table has a unique autonumber "internal ID" field, but this field is not always used as the primary key. My question In...

Any way to run just the current statement on SQL Server?

As a long time Toad for Oracle user, I have gotten used to hitting Ctrl+Enter and having just the statement under the cursor be executed. In SQL Server Management Studio, hitting F5 runs the entire script. To run just the current statement, I have to manually highlight the statement I want, and then hit F5. That is really annoying to m...

Concatenate ntext in SQL Server 2005

Hi, I need to concatenate 2 ntext columns into one. I can't convert them to nchar, cause both contains strings longer than 4000 chars. Is there a way to do this in SQL Server 2005? ...

Can I xcopy a sqlserver db and log file to my new computer?

Can I xcopy a sqlserver db and log file to my new computer? UPdate the db is on a hard drive that is not in a computer anymore, that is why I ask if I can just xcopy ...

tsql user-defined functions

Is it possible to call a user-defined function in TSQL without the scoping qualifier. I want to call select myfunc(var) and not select dbo.myfunc(var) select myschema.myfunc(var) It's possible in every other DB that I've ever worked with (7 others) it has to be possible in tsql too. If I'm signed into my DB/schema I don't have to ...

What service accounts to use when installing SQL Server 2008 on a Dev Box

I am installing SQL Server 2008 on my development machine and during the install I am asked to assign accounts to the different services. What account should I use for the services where no user has been assigned if this is a simple development machine? Can I use the account I am logged in with (I am the only user on this machine)? Sho...

Why do SQL Server Views needs to be refreshed every once in a while

I'm doing quite a lot of backend developing the past few days, and as we're working with central database scripts, I just write plain old SQL upgrade scripts, and execute them to the database. Well fine and all, but why do have to write 'refresh view' scripts, and execute them every time I add or edit some fields to a view. SQL Server ...

sql server 2008 restore with transaction log?

I am developer so need your advice on how to plan for it I am having sql server 2008. I am going to through what they have in maintance wizard And found that they have full, differential and transaction log. So if i take one full back once a week then differential backup every day. Not sure how transaction log fit into this. I assum...

SQL Server 2005: Why Name Transactions?

I've been sorting out the whole nested transaction thing in SQL server, and I've gleamed these nuggets of understanding of behavior of nested trans': When nesting transactions, only the outermost commit will actually commit. "Commit Trans txn_name", when nested , will always apply to the innermost transaction, even if txn_name refers t...