sql-server-2008

How to list column headers of a SQL Server table using sp_help perhaps?

Hi, I have a few tables with 70-80 columns in them. I would like to populate them with somewhat random data, unless I will not be able to do so due to key violation, etc. The first step would be simply to get the list of all headers. There seem to be two ways: A) Run select * from table_of_interest; in MSFT SQL Server Management Studi...

dynamically creating the #temp table and then used to insert the data

Hi All, I am importing an intermediate result of query into a temp table for further use, so I used a #temp table to maintain the same schema as select * into # temp from schema.tableName where 1<>1; insert into # temp from exec(table) While I am doing this statement as a variable to pass the different tableName its not working SET ...

Algorithm for Search page

Hi All, I am creating a search page where we can find the product by entering the text. ex: Brings on the night. My query bring the records which contain atleast word from this. Needs: 1. First row should contains the record with the given sentence. 2. second row next most matching. 3. Third row next matching ...etc How to ac...

What is the suggested approach to Syncing/Backing up/Restoring from SQL Server 2008 to SQL Server 2005

I only have SQL Server 2008 (Dev Edition) on my development machine I only have SQL Server 2005 available with my hosting company (and I don't have direct connection access to this database) I'm just wondering what the best approach is for: Getting the initlal DB Structure & Data into production. And keeping any structural changes/da...

Correct escaping of delimited identifers in SQL Server without using QUOTENAME

Is there anything else that the code must do to sanitize identifiers (table, view, column) other than to wrap them in double quotation marks and "double up" double quotation marks present in the identifier name? References would be appreciated. I have inherited a code base that has a custom object-relational mapping (ORM) system. SQL ...

What is the performance of "Merge" clause in sql server 2008?

Hi, Merge can performs insert, update, or delete operations on a target table based on the results of a join with a source table. For example, you can synchronize two tables by inserting, updating, or deleting rows in one table based on differences found in the other table. Is anyone familiar with the performance to use "Merge" versus t...

What is the mysql 5.5 equivalent for the sys.dm_fts_index_keywords_by_document in sql 2008

I'm making a web application that uses the data in the sys.dm_fts_index_keywords_by_document. I'm interested how many times a given term occurs in each string that is indexed. For example, I have a table with a column called comments, the table has various strings in the comments field. When I make that column full text searchable, the...

DBCC SHRINKFILE 1 sproc for multiple databases

I have a need to execute DBCC SHRINKFILE for multiple db's within the same sproc. I could create multiple sprocs so it runs within the given context, but I was curious if there were alternatives? ...

How to put foreign key constraints on a computed fields in sql server?

Table A has a computed field called Computed1. It's persisted and not null. Also, it always computes to an expression which is char(50). It's also unique and has a unique key constraint on it. Table B has a field RefersToComputed1, which should refer to a valid Computed1 value. Trying to create a foreign key constraint on B's RefersT...

SQL Server Upgrade 'Developer > Enterprise'

Hey guys, My company purchased Visual Studio Pro 2008 last year, which had a 'free' copy of SQL Server Developer, which I have been using for development. We are wanting to upgrade the copy of developer edition to enterprise (As we now want to use the server as a production server), and have purchased the licenses for this. Now... Mor...

SQL Server 2008. I want to be able to edit multi line character data like I used to be able to in Enterprise Mgr

I want to be able to insert and update rows with embedded carriage returns even if the column if of type text or ntext. Since there seems to be no GUI way to do this, does anyone know of a free tool that does? ...

Using SQL Server Analysis Services with Sybase Advantage Database Server

Is it possible to use SQL Server 2008 Analysis Services with data stored in Sybase Advantage Database Server? Either directly, or via SQL Server Integration Services. ...

SQL Server: How to trim all columns in a table

I have over 30 columns in my table (sql server 2008). Columns type are varchar(x). I know that in every column there is two extra spaces at the end of column value. How to use rtrim function for all columns and save this modification into this existing table? Edit: is there a way to do it using stored procedure or cursor where I don't h...

Getting a permission error when trying to connect to sql database

I have a sql server on a dedicated machine, running SQL 2008. I have the IP of the box, a database setup on it. I've built a small script that just does a connection test, and when I run it, I get the following error. Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture...

SQL Server 2008: How to find trailing spaces

How can I find all column values in a column which have trailing spaces? For leading spaces it would simply be select col from table where substring(col,1,1) = ' '; ...

Multi-statement Table Valued Function vs Inline Table Valued Function

A few examples to show, just incase: Inline Table Valued CREATE FUNCTION MyNS.GetUnshippedOrders() RETURNS TABLE AS RETURN SELECT a.SaleId, a.CustomerID, b.Qty FROM Sales.Sales a INNER JOIN Sales.SaleDetail b ON a.SaleId = b.SaleId INNER JOIN Production.Product c ON b.ProductID = c.ProductID WHERE a.ShipDate IS...

How sql server evaluates the multiple different joins?

Hi, i have a general question about how sql server evaluates the joins.The query is SELECT * FROM TableA INNER JOIN TableB ON TableB.id = TableA.id LEFT JOIN TABLEC ON TABLEC.id = TABLEB.id Q1: What tables is the left join based on? I know it will based on the TABLEC but what is the other one? Is it the result of the first inner jo...

SQL Server 2008 Table Maintenance - Rebuild, Reorganize, Update Stats, Check Integrity etc HELP!

I'm migrating a ~15GB database from SQL Server 2005 to a new server running SQL Server 2008, and along with that I need to create all the new Maintenance Plans. I can take care of all the backup stuff, but the table maintenance baffles me some. Does anyone have any input on how often I should (or how often you do would suffice too) the...

Where are the assemblies to interact with Sql Server?

Hi, I am running Visual Studio 2010 Ultimate and SQL Server 2008 R2 Nov 2009 CTP. However, I cannot find the .dlls for Sql Server (So that I can add tables, get the databases collection, etc). Can anyone tell me where dlls are based? Thanks ...

SQL Server 2008 - Shrinking the Transaction Log - Any way to automate?

I went in and checked my Transaction log the other day and it was something crazy like 15GB. I ran the following code: USE mydb GO BACKUP LOG mydb WITH TRUNCATE_ONLY GO DBCC SHRINKFILE(mydb_log,8) GO Which worked fine, shrank it down to 8MB...but the DB in question is a Log Shipping Publisher, and the log is already back up to some 5...