sql-server-2005

Dropping noise words in SQL Server 2005 full text indexing

人盡茶涼 提交于 2019-12-18 18:29:37
问题 In a pretty typical scenario, I have a 'Search' text box on my web application which has user input passed directly to a stored procedure which then uses full text indexing to search on two fields in two tables, which are joined using appropriate keys. I am using the CONTAINS predicate to search the fields. Before passing the search string in, I do the following: SET @ftQuery = '"' + REPLACE(@query,' ', '*" OR "') + '*"' Changing the castle to "the*" OR "castle*" , for example. This is

What is the benefit of having varbinary field in a separate 1-1 table?

随声附和 提交于 2019-12-18 18:21:06
问题 I need to store binary files in a varbinary(max) column on SQL Server 2005 like this: FileInfo FileInfoId int, PK, identity FileText varchar(max) (can be null) FileCreatedDate datetime etc. FileContent FileInfoId int, PK, FK FileContent varbinary(max) FileInfo has a one to one relationship with FileContent. The FileText is meant to be used when there is no file to upload, and only text will be entered manually for an item. I'm not sure what percentage of items will have a binary file. Should

What is the benefit of having varbinary field in a separate 1-1 table?

三世轮回 提交于 2019-12-18 18:21:04
问题 I need to store binary files in a varbinary(max) column on SQL Server 2005 like this: FileInfo FileInfoId int, PK, identity FileText varchar(max) (can be null) FileCreatedDate datetime etc. FileContent FileInfoId int, PK, FK FileContent varbinary(max) FileInfo has a one to one relationship with FileContent. The FileText is meant to be used when there is no file to upload, and only text will be entered manually for an item. I'm not sure what percentage of items will have a binary file. Should

Most efficient way to query multiple identical tables in separate databases

让人想犯罪 __ 提交于 2019-12-18 17:56:12
问题 I have a server (SQL Server 2005) with multiple archive databases (1 per quarter stretching back 8 years) that are all structurally identical. I frequently need to query back over a certain date range that spans n databases, usually n is small 1-3 but it's possible I need to query the whole set. Any thoughts n the most efficient way to do this both from a code cleanliness and a performance perspective? Current solutions are rather ad-hoc, there are a collection of views that span all or just

Create a new db user in SQL Server 2005

丶灬走出姿态 提交于 2019-12-18 15:51:52
问题 how do you create a new database user with password in sql server 2005? i will need this user/password to use in the connection string eg: uid=*user*;pwd=*password*; 回答1: CREATE LOGIN [user] WITH PASSWORD='password', DEFAULT_DATABASE=[your_db], CHECK_POLICY=OFF GO CREATE USER [user] FOR LOGIN [user] EXEC sp_addrolemember N'db_datareader', N'your_db' EXEC sp_addrolemember N'db_datawriter', N'your_db' GO Where CHECK_POLICY=OFF switches off password complexity check, etc 回答2: As of SQL Server

Compare two sets of XML data using XQuery in SQL Server

此生再无相见时 提交于 2019-12-18 15:50:08
问题 Suppose I store employee data in a xml column in my log table. Sometimes data is also updated in the xml column from a stored procedure. Here is the sample example DECLARE @XML1 XML DECLARE @XML2 XML SET @XML1 = '<NewDataSet> <Employee> <EmpID>1005</EmpID> <Name> keith </Name> <DOB>12/02/1981</DOB> <DeptID>ACC001</DeptID> <Salary>10,500</Salary> </Employee> </NewDataSet>' SET @XML2 = '<NewDataSet> <Employee> <EmpID>1006</EmpID> <Name> keith </Name> <DOB>05/02/1981</DOB> <DeptID>ACC002</DeptID

Correct escaping of delimited identifers in SQL Server without using QUOTENAME

不羁岁月 提交于 2019-12-18 15:37:06
问题 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 cannot be written in the application but the ORM must still eventually generate the SQL to send to the SQL Server. All identifiers are quoted with double

SQL Server BIGINT or DECIMAL(18,0) for primary key

爷,独闯天下 提交于 2019-12-18 15:33:58
问题 We have a SQL Server 2005 database for which we want to improve performance of bulk delete/insert/selects and I notice it uses decimal(18,0) for its primary keys. I understand this will give us many more values than bigint but was hoping it might be a quick win and should last us for many million years of growth by my calculations. I see in the .net docs decimals take 16 bytes instead of the 8 required by longs but in SQL Server it looks like bigint take 8 bytes but the decimal(18,0) takes

create foreign key without a primary key

一笑奈何 提交于 2019-12-18 15:12:17
问题 Why is it necessary to have a primary key on a column of one table to which a column of the other table having foreign key references. create table D(Did int) create table E(Eid int foreign key references D(Did)) The above query gives error: There are no primary or candidate keys in the referenced table 'D' that match the referencing column list in the foreign key 'FK__E__Eid__79C80F94'. 回答1: Easy. If you have 2 values the same in the parent table, how do you know which one to associate child

create foreign key without a primary key

为君一笑 提交于 2019-12-18 15:11:28
问题 Why is it necessary to have a primary key on a column of one table to which a column of the other table having foreign key references. create table D(Did int) create table E(Eid int foreign key references D(Did)) The above query gives error: There are no primary or candidate keys in the referenced table 'D' that match the referencing column list in the foreign key 'FK__E__Eid__79C80F94'. 回答1: Easy. If you have 2 values the same in the parent table, how do you know which one to associate child