sql-server-2008

SQL 2000/2005/2008 - Find Unique Constraint Name for a column

Hi, I have a table with a column that needs the data type upgrading. However running any alter script causes errors due to a unnamed unique constraint. I need to drop this constraint but unfortunately I do not know the name. I have a script which currently lists all the unique constraints on the table but I need to find out how to go...

SQL Server 2008 Optimize FULL JOIN with ISNULL statements

HI All I was hoping someone could help me improve a query I have to run periodically. At the moment it takes more than 40 minutes to execute. It uses the full allocated memory during this time, but CPU usage mostly meanders at 2% - 5%, every now and then jumping to 40% for a few seconds. I have this table (simplified example): CRE...

Why does new T-SQL of SQL Server 2008 work on database in compatability mode 80 ?

Experimenting with new features of T-SQL, I've run into a puzzle. Here is some new syntax supported by SQL 2008 and I'd expect it to work on databases set for compatibility mode 100 (i.e. 2008) and not work for compat mode 80 (i.e. 2000). Yet this works for a database set for SQL SERVER 2000 compatibility mode on a SQL 2008 instance of S...

How to run the VS2010 Sql Server project's deployment script

I'm confused, if I select the "Create a deployment script" option and 'deploy' the project, i get a SQL file that uses non-SQL syntax for variables like $database. How can I execute that deployment script? I'm pretty sure SQL Server management Studio doesn't understand the syntax. It seems to me the only way to actually deploy, is to...

SQL Server: get all parent child URL's from a single table

I have a table that looks like this: Slug | Parent | MetaTitle | MetaDescription | MetaKeywords The Url's on the site are built by appending the slug to the parent as long as the parent is not null. So if I have data like so: Slug | Parent ----------------------------------------- Home null About n...

T-SQL query to remove non matching value from ColumnA where value doesn't exist in ColumnB

I have two databases, with the following tables: DatabaseA TableA ColumnA (varChar(10) DatabaseB TableB ColumnB (varChar(10) I need a query that: Ignores NULLs or empty strings Finds rows where the value of ColumnA does not exist in columnB In this case, replaces the value of the non matching row in ColumnA with '' (empty string)...

Add a namespace on an xml generated by a query

I try to add a namespace on xml using WITH XMLNAMESPACES. When I execute my queries, the namespace is added with the root element but with the second element I have xmlns="" as well... and I would like to remove that... I provided an example: Queries for creating the table and the data: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON G...

Why should GRANT be written after GO in a SQL Stored Procedure?

We had a Stored Procedure written and it had a GRANT written at the last line of the SP.. Our DBA recommended that there should be a GO before the GRANT statement, else it will be executed every time. What does this mean? I am not sure how GO will prevent GRANT executing "every time". ...

How to transfer data from Microsoft Access to SQL server 2008?

Hi friends, In my current project i have to transfer data EVERY DAY from MS Access to Sql Server 2008 standard edition. of course i can use SQL Migration tool to transform Access database into Sql Server database, but problem is i have to do this again and again every day to keep updating my sql server database. SO is there any way i c...

SQL Server 2008 installing certificate issued to outer name

Does anyone know how to bind to SQL server 2008 sertificate that doesn't issued to the server local name? I need to connect to a data-base from other domain over ssl. the SQL server 2008 server has an inner name inside the domain (private name) and name for accessing it from the outer network, WAN (outer name). I am trying to install a...

Simple Stored Procedure Question

I am creating a simple stored procedure in VS 2010/SQL Server 2008 as follows: CREATE PROCEDURE ReturnPrice @carID int @price decimal(18,2) output AS SELECT @price = Price FROM Cars WHERE CarID = @carID and I am receiving the following error message when attempting to save: Incorrect syntax near '@price' Must declare the scalar ...

Replicating Data from One DB to another

Hey Guys, Im wondering if you could point me to a few possibilities in the best way to move/replicate data from one database on a different server to my database. Ideally any update on the other database would be immediately pushed to mine. Another thing i was thinking about ok lets say the master database has 100 tables I could build...

Use of Execute As User in SQL 2008

We are transitioning from SQL Server 2005 to 2008 and suddenly our Execute As User statements aren't working. Did something change between these 2 releases? ...

SQL Server 2008: Fill multiple T-SQL variables from one SELECT query?

To fill one variable with a value from a query I can write following: SET @TargetID = (SELECT TOP 1 ID FROM @bigDataSet ORDER BY date DESC) To fill multiple variables from this query, eg. something like: SET (@TargetID, @TargetName) = ....(SELECT TOP 1 ID, [Name] FROM @bigDataSet ORDER BY date DESC) what can I write? ...

Querying for ae matches æ in SQL Server / LINQ to SQL

When I try running... SELECT * FROM Users WHERE Username = 'ae' it returns matches where the username is æ (ash character). I was wondering if there's a way to support characters like the ash character but get an exact match for what I'm looking for. I'd like to search for ae and get just ae, not ae and æ I'm using SQL Server 2008 an...

A weird sql server insert problem ?

UPDATE : I have this SSMS tools pack which wraps everything in this - BEGIN TRAN ROLLBACK When I removed above lines and just ran the proc....everything works fine...I guess it was doing an rollback...as SQLMenace said...my bad i guess...never happened before so i was quite confused....anyways...thanks..hopefully it will help som...

Compare Monday's data to previous Mondays in SQL Server

I am trying to figure out how to compare the current day's data to the same data from a week ago, 2 weeks, etc. Let's say I have a table called "Order" with 2 columns: Order table ----------- OrderID int identity OrderDate datetime If today, is Monday, I would like to be able to compare the number of orders from today to the previous...

SQL Server 2008 Geometry not working?

Hi There. I'm having an issue with SQL Server 2008 and the geometry functions. I'm trying to create non-overlapping shapes using the STDifference function... but it does not seem to be working 100% of the time. Here is all the sample code to demonstrate the issue. Anybody have any idea to make these non-overlapping polygons? (except ...

Take db script in sql server 2008 (only updates)

Hi, I want to generate the database script of sql server 2008. I want to generate only updates from particular date. how to do this? ...

SQL Server does not use an index comparing datetime to not null

Hello, I have a simple table not related to any other. It has a not PK column that it is a date. I have created a non-clustered index to that column. If I make this query: select * from table where datecolumn is not null <-- does not use the index and goes really slow. But if I remove the not, this way: select * from table where datec...