sql-server

MS SQL Server trigger to update item rating and number of votes

To make this easier to understand, I will present the exact same problem as if it was about a forum (the actual app doesn't have to do with forums at all, but I think such a parallel is easier for most of us to grasp, the actual app is about something very specific that most programmers won't understand (it's an app intended for hardcore...

Can you order your values differently to your columns on an insert statement?

Is there a way to name or guide your values in an insert statement? eg. declare @temp TABLE ( column1 int, column2 int, column3 int ) insert @temp(column1, column2, column3) Select 1 as column1,3 as column3, 2 as column2 select * from @temp will return a 3 in column2 when I would like the 2 in column2 and 3 in column3. ...

sql server: import operation won't copy full schema

I recall that the import tool in sql server 2000 would copy indexes, relationships, etc. In sql server 2005/2008 the import tool in SSMS will only create the tables, copy the data, but the keys, indexes, relationships are missing. I can find no option in the import wizard to enable this? What am I missing here? Is this not possible anym...

Slow distinct query in SQL Server over large dataset

We're using SQL Server 2005 to track a fair amount of constantly incoming data (5-15 updates per second). We noticed after it has been in production for a couple months that one of the tables has started to take an obscene amount of time to query. The table has 3 columns: id -- autonumber (clustered) typeUUID -- GUID generated before ...

Update an Access Link Table when the underlying SQL Server table's columns change

At work we've got a SQL Server database that several users connect to (read only) using Access 2003. This was fine, except now one of the tables they look at is re-created fairly often and part of this process involves a cross-tab query. Which means that, depending on the data, the number and and names of the columns potentially change...

Subsonic - How to use SQL Schema / Owner name as part of the namespace?

Hi there, I've just started using Subsonic 2.2 and so far very impressed - think it'll save me some serious coding time. Before I dive into using it full time though there is something bugging me that I'd like to sort out. In my current database (a SQL2008 db) I have split the tables, views, sps etc. up into separate chunks by schem...

How to kill own Windows Service

A WCF service is hosted in a Windows Service (WS). When the database (SqlServer 2005) goes down a SqlException is thrown due to the actions performed on the database. What I want to accomplish is that the WS - where the WCF service is hosted - should go down when the DB is also down. The WS will be restarted manually by the way. My...

Can Reporting Services 2008 be used with SQL Server 2005 as the catalog database?

Can you set up a Reporting Services 2008 reports server to use SQL Server 2005 for the report catalog database? ...

To get difference between 2 dates

hi guys, I have 2 dates. I want to get number of days between 2 dates in storedprocedure. ...

Strange behavior of sql server

Hey guys, I have following table structure in my DB ID Name -------------------------- ID_1 Name1 ID1 Name2 when I execute the following query SELECT * FROM tblNames WHERE ID LIKE '_1' I get both records selected... any suggestions how to get rid off it?? ...

Declaring an Index as unique in SQL Server

If I know an index will have unique values, how will it affect performance on inserts or selects if I declare it as such. If the optimiser knows the index is unique how will that affect the query plan? I understand that specifying uniquenes can serve to preserve integrity, but leaving that discussion aside for the moment, what are the...

Deleting columns in MS SQL Server 2005

How do I delete a column from an existing table? ...

Calling a function on the server and getting back the results by the client

We have a winform application that needs to display some results calculated on the DB that exists on a server. In the current solution, we have a VPN connection that connects us to the server database, we query the data from the server DB using a normal SQLConnection . We get the data, then we do the calculation at the client side For b...

What does the N in varchar(N) refer to

What does the N in varchar(N) refer to when describing a field in a database. Is it the number of characters or bytes. Also, one is using UTF-8, a character may use more than one byte. ...

What happens when you restore system databases to a SQL Server with a different name?

I'm currently looking at disaster recovery plans and restoring backups of master/msdb/model. In theory if I restore master, msdb, model and the user databases onto a fresh server install (with the same service packs etc) then I will have an exact copy of the original server, with all the maintenance plans and jobs and everything. But w...

sql function to return table of names and values given a querystring

Anyone have a t-sql function that takes a querystring from a url and returns a table of name/value pairs? eg I have a value like this stored in my database: foo=bar;baz=qux;x=y and I want to produce a 2-column (key and val) table (with 3 rows in this example), like this: name | value ------------- foo | bar baz | qux x | ...

Changing dateformat on a SQL Server DB and not on whole server to dd/mm/yyyy

Hi there, can anyone help, we have a sql server 2005 database installed (actually its an sql server 2000 attached to an sql server 2005 server) with the default server language language USA with dateformat like mm/dd/yy and we really need to keep it this way but currently just uploaded a new database to the server and this needs to have...

Simple Query to Grab Max Value for each ID

OK I have a table like this: ID Signal Station OwnerID 111 -120 Home 1 111 -130 Car 1 111 -135 Work 2 222 -98 Home 2 222 -95 Work 1 222 -103 Work 2 This is all for the same day. I just need the Query to return the max signal for each...

How to retrieve field names from temporary table (SQL Server 2008)

I'm using SQL Server 2008. Say I create a temporary table like this one: create table #MyTempTable (col1 int,col2 varchar(10)) How can I retrieve the list of fields dynamically? I would like to see something like this: Fields: col1 col2 I was thinking of querying sys.columns but it doesn't seem to store any info about temporary ...

Doing SQL Server backups - FULL / DIfferential and how often?

Hi there, Can anyone let me know what is the best practice for doing sql server backups i.e. FULL, differential and partial differential I will doing this from code using SMO (c#) but anyway... is it best to do a FULL backup every 1 month and a differential every day?? Just looking for a bit of guidance really Any ideas? ...