sql-server-2008-r2

Getting top n latest entries from SQL Server full text index

徘徊边缘 提交于 2019-12-07 14:14:58
问题 I have a table in a SQL Server 2008 R2 database Article (Id, art_text) Id is the primary key. art_text has a full text index. I search for latest articles that contain the word 'house' like this: SELECT TOP 100 Id, art_text FROM Article WHERE CONTAINS(art_text, 'house') ORDER BY Id DESC This returns the correct results but it is slow (~5 seconds). The table has 20 million rows and 350,000 of those contain the word house. I can see in the query plan that an index scan is performed in the

How I can get table definition in SQL SERVER 2008 R2 using SQL query?

戏子无情 提交于 2019-12-07 12:39:18
问题 I have created a sample java program in which I get the definition of all objects like views, triggers, functions, etc. using the following queries:- select object_definition(object_id) from sys.objects where type='V'; //for Views select object_definition(object_id) from sys.objects where type='TF'; //for Functions select object_definition(object_id) from sys.objects where type='TR'; //for Triggers select object_definition(object_id) from sys.objects where type='P'; //for Stored Procedures

SQL Server WHERE Condition does not consider white spaces

老子叫甜甜 提交于 2019-12-07 12:39:08
问题 I have first name and last name with trailing white spaces. I have two SQL queries – the first query is returning result even if I search with no white space. (The first query is returning unwanted result). Is this behavior consistent in all versions of SQL Server? Is it a known behavior? Is it documented anywhere in msdn for SQL Server 2008 R2 ? CODE DECLARE @NameTable TABLE (first_name varchar(40),last_name varchar(40)) INSERT INTO @NameTable VALUES ('STEVEN ','STANLEY '); --QUERY 1 SELECT

using SqlCmd variables with dbDacFx provider of MsDeploy

空扰寡人 提交于 2019-12-07 12:20:48
问题 I am trying to use msdeploy using dbDacFx provider to deploy my dacpac file. This database project uses a variable named UserName to create logins and users etc. Value for this needs to be passed during deployment time. So i am doing something like ... msdeploy.exe -verb:Sync -Source:dbDacFx="c:\dev\pmwuiservices\trunk\Build\database\Database.dacpac"-dest:dbDacFx="Data Source=localhost;Integrated Security=True;Database=UIConfig", -setParam:Kind=SqlCommandVariable,scope=dbDacFx,match=UserName

SQL get rows in '= ALL' style

我们两清 提交于 2019-12-07 12:18:15
问题 I have simple many-to-many relation in table Product_Category (MSSQL 2008 r2): CREATE TABLE #Product_Category (ProductId int, CategoryId int); go INSERT INTO #Product_Category (ProductId, CategoryId) VALUES (1, 200); go INSERT INTO #Product_Category (ProductId, CategoryId) VALUES (2, 200); go INSERT INTO #Product_Category (ProductId, CategoryId) VALUES (2, 400); go INSERT INTO #Product_Category (ProductId, CategoryId) VALUES (3, 300); go INSERT INTO #Product_Category (ProductId, CategoryId)

How do I exclude rows when an incremental value starts over?

主宰稳场 提交于 2019-12-07 12:08:47
问题 I am a newbie poster but have spent a lot of time researching answers here. I can't quite figure out how to create a SQL result set using SQL Server 2008 R2 that should probably be using lead/lag from more modern versions. I am trying to aggregate data based on sequencing of one column, but there can be varying numbers of instances in each sequence. The only way I know a sequence has ended is when the next row has a lower sequence number. So it may go 1-2, 1-2-3-4, 1-2-3, and I have to figure

FLWOR in Sql server count number of hits

依然范特西╮ 提交于 2019-12-07 11:45:20
问题 I am using SQL Server 2008 R2. My problem is that I want to count number of hits that i receive from XQuery query using FLWOR. For each hit, I want a consecutive number, like: 0,1,2,3,4... My query: select @xml.query('for $s at $count in /Root/Persons/Person return <Person ID="{$count}">{$s}</Person>') The only problem here is this is not supported in SQL Server and I receive an error: Msg 9335, Level 16, State 1, Line 16 XQuery [query()]: The XQuery syntax 'at' is not supported. I've also

How to drop all of the indexes except primary keys with single query

為{幸葍}努か 提交于 2019-12-07 09:48:39
问题 I am planning to drop all of the indexes except the primary keys. I made the primary keys myself but all other indexes was suggestion of SQL Server. After dropping all indexes which are not primary keys, planning to use SQL Server profiler tuning template for database tuning advisor and create indexes. With this way planning to not have unused indexes or performance degrading indexes. How logical is this ? Thank you. 回答1: DECLARE @sql NVARCHAR(MAX) = N''; SELECT @sql += N'DROP INDEX ' +

how to know if SSIS is installed in my SQL SERVER 2008 R2

让人想犯罪 __ 提交于 2019-12-07 08:49:08
问题 I have sql server 2008 r2, I want to put my stored procedures in packages, i search the internet , i see that i have to install a data tool from microsoft for that. but this tool needs to be SSIS installed in SQL SERVER 2008 R2, how do i know if i have it ? thank u this is my sql server 2008 r2 回答1: You can go to SQL Server Configuration Manager (usually available in Start>Sql Server 2008 R2> Configuration Tools). Once launched, you have access to all available services. If Sql Server

Encrypting database tables in SQL Server 2008

廉价感情. 提交于 2019-12-07 08:45:38
问题 I have a Windows application using a database in SQL Server 2008. I do not want users to see the database tables. How can I encrypt tables in my database? 回答1: You have different options here. You can use symmetric encryption for your data: CREATE TABLE sales ( ... ) Create symmetric key: CREATE CERTIFICATE cert_sales WITH SUBJECT = N'Sales certificate', START_DATE = N'2009-01-01', EXPIRY_DATE = N'2018-12-31'; CREATE SYMMETRIC KEY symkey_sales WITH ALGORITHM = AES_256 ENCRYPTION BY