sql-server-2008

SQL Server 2008 Stored Procedure

I cannot store the date data type variables using stored procedure. My code is: ALTER PROCEDURE [dbo].[Access1Register] -- Add the parameters for the stored procedure here @MobileNumber int, @CitizenName varchar(50), @Dob char(8), @VerificationCode int AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- inter...

How do you actually use Visual Studio Team System database projects to version Sql Server

How are you supposed to correctly use a Visual Studio Team System database project to implement version control on a sql server database? This might seem overly generic but everything I've found so far online hasn't helped me in being able to achieve anything useful. I have managed to find functionality that appears to be similar to fea...

add column while copying data in sql

I'm using SqlBulkCopy to bulk insert some records from one table into another table. The query is using a SqlDataReader to get the data. The one difference that matters (besides column order which is handled in the mappings) between the tables is that the destination table has a date column into which the current date needs to be added...

Is there an index on the primary key of a table?

Does having a primary key column mean there is an index on that column? If so, what kind of index is it? ...

Why does SSIS Lookup task output a DT_TEXT type even though the value returned through the lookup is a VARCHAR(50)?

Running SQL Server Integration Services (64-bit install of SQL Server 2008 Developer) on a 64 bit version of Windows 7 Professional. I have a simple SSIS package which imports data from a delimited text file, does a lookup to a SQL Server table, joining on a key field (int) and returns the UserName (varchar(50)) from that table. Sample...

Getting info about running update query

On Sql Server 2008, I have a slow-running update query that has been working for 3 hours. Is there any way to get any statistics (say, how many rows have changed so far or something else) about this execution (of course, while executing) ? So that I can make a decision between canceling query and optimize it or let it finish. Or else, s...

Can SQL Server Compact be used as both a Source and Destination in SSIS?

I'm wondering if SQL Server Compact Edition can be used as both a Source and Destination in an SSIS dataflow. I know I can setup a SQLMOBILE connection manager, and I've found some information that mentions using it as a Destination, but nothing on using it as a Source. What I'm looking to do is to transfer data from one SQL Server Com...

SQL Server 2008 backup best practices

Without not reason, I lose all my data in my database. Fortunately this is was just test data, but this made me to think what will happen if this was done with a production db. Ultimately, every developer got a db problem and wan to role-bake the db. We don't do things to protect the db, as we think its a DBA work, but then we got trou...

Automated Filegroup Migration in SQL Server

Recently I've been trying to restructure an old database that was not designed with filegroups (just the default PRIMARY) and, among other things, move a bunch of tables to a new Data filegroup residing on a SAN. I know how to migrate the data: ALTER TABLE MyTable DROP CONSTRAINT PK_MyTable WITH (MOVE TO [MyDB_Data]) ALTER TABLE MyTab...

SQL View or Table

I have a table of data that gets update once a week. I then have a query that process this data and essentially returns a list of codes and the amount of hours booked to those codes. This query is reasonably complicated and takes about 5 seconds to run. This data needs to be used by a lot of other query's in the DB, so I want to put it ...

Remove (merge) SQL Servers' database secondary data file

I have a database backup for which SQL Server Management Studio says that it has three files in it: an .mdf file, an .ndf file and one .ldf file. This secondary data file (the .ndf one) was created for no obvious reason, so I want to remove it altogether (without losing data, of course), preferably during while the database is being rest...

How to create a relationship between table and view in the Entity Framework

I have an Entity Framework model that was generated by the Visual Studio 2008 wizard based on a Sql Server 2008 database. The model has a view that logically is joined in a many-to-many relationship with another table through a join table (enforced in the database by an insert/update trigger). Both tables and the view are part of the...

stored procedure column value determined by value of another column

I have a table of data something like this. date, amount, price 2009-10-12, 20, 15.43 2009-10-13, -10, 6.98 I need to write a stored procedure that will return these column as well as create a new column that indicates whether the amount was positive or negative. So the end result of the procedure would look something like this. dat...

SQL Server 2008 Database (How to lock it from copying and attach it in another machine)

I have a database with data that i don't want anyone to copy around. Now, how can i prevent other users to have access in the local machine, but whenever i want to work with, i am allowed. And another issue I'm thinking, how can i lock the DB so if someone copy the .mdb file and try to attach it on another machine he/she couldn't see ...

"Insufficient System Memory" Error in SQL Server 2008

I get the following error in SQL Server 2008: There is insufficient system memory in resource pool 'internal' to run this query. I recently migrated from SQL Server 2000 to SQL Server 2008, and the system is Windows Server 2K8. ...

How to import data with SSIS for sequential guids?

Is there anyway to import data into SSIS where I expect the PKs to be sequential guids? The only method I've been able to come up with so far is to create a temporary table with the column defaulting to newsequentialid() loading the data in there then copying it to the correct table. This isn't very elegant and is somewhat time consumin...

get column data in stored procedure when schema is reversed

In a SQL 2008 DB there are 2 tables of data that I need to use to build a result in a stored procedure. Table 1 looks something like this. date name hour amount price ------------------------------------------ 2009-10-12 tom 12 20 15.43 2009-10-13 fred 16 -10 6.98 Table 2 looks like this. Note ...

SQL - shrink database log file

I am trying to shrink my database log file. I have tried to run: USE databasename BACKUP log databasename WITH truncate_only DBCC shrinkfile (databasename_log, 1) I get the error message: Msg 155, Level 15, State 1, Line 3 'truncate_only' is not a recognized BACKUP option. Am I missing something? ...

getting "select permission denied" error when using sp_executesql in proc (Sql Server 2008)

I'm using Sql Server 2008 and have a proc that uses sp_executesql inside. I keep getting the following error when executing the proc through ASP.NET: The SELECT permission was denied on the object 'MyTable', database 'MyDatabase', schema 'dbo'. I've done lots of research on this and most people point to the fact that I need to grant se...

SQL2008 geography query to JPG

I'd like to take the results of a SQL geographic query, and create a JPG - something similar to what you see in the 'spatial view' tab. I'm doing this for 200+ query, so something I can automate could be nice. Does an app already exist to do this, or do I need to write it myself? ...