sql-server-2008

Table design options for large number of rows?

I have an application that sends data based on user interaction (not user input). The data sent could be an Integer, String, Date, or Boolean value. There are 140 keys. We may get anywhere from 1 key value pair to all 140 at a time. We want to store everything but will only be using 20 out of 140 keys within the application. The remaini...

How to control what users can decrypt SQL Server Symmetric Key Encryption

I am looking into encrypting some sensitive data in SQL Server, such as bank account numbers and social security numbers in order to comply with new state laws. I am using SQL Server 2008 as my database with .NET code. I have used .NET to encrypt passwords, but for this I'm thinking of using Microsoft's built in encryption by just encryp...

sql server stored proc times out and query does not time out, why ?

I have a stored proc on sql server 2008 that excepts a int parameter. It does call other stored procs and have nested quires. the problem i am facing is when i run the procedure from SQL server management studio it does not execute and times out. If i run the queries in side the stored proc separately in another SQL server management s...

Using comparison operators in SELECT clause of T-SQL query

How to select a result of comparison operator as a field with type BIT? How it does work in C#: bool isGreater = FieldA > FieldB; How it doesn't work in T-SQL: SELECT (FieldA > FieldB) AS BIT FROM t How to write such task properly? ...

Sql Server 2008 not reporting compile errors for missing objects

SQL Server 2008 doesn't always report a compile error when a stored procedure references an object that doesn't exist. Is there a way to cause it to always report errors? ...

Find broken objects in SQL Server

Is there a tool that will find all objects in SQL Server (functions, procs, views) that cannot possibly work because they refer to objects that don't exist? ...

Insert 2 rows that are related in both directions in SQL

I have two tables kinda like this: // Person.Details Table: PersonID int [PK] | EmployeeCreatorID int [FK] | FirstName varchar | OtherInfo... // Employee.Details Table: EmployeeID int [PK] | PersonID int [FK] | IsAdmin bit | OtherInfo... Each table is related to the other: [Employee.Details.PersonID]===>[Person.Details.PersonID] AND...

Modify SQL result set before returning from stored procedure

I have a simple table in my SQL Server 2008 DB: Tasks_Table -id -task_complete -task_active -column_1 -.. -column_N The table stores instructions for uncompleted tasks that have to be executed by a service. I want to be able to scale my system in future. Until now only 1 service on 1 computer read from the table. I have a stored proc...

help in sql query

i have a table that has id,fromdate and todate as columns. i need to select the ids that is between 2dates specified by the user. for example: ID FromDate ToDate 1 2010-01-10 2010-01-13 2 2009-03-20 2010-01-09 so if the user entered datefrom=2000-00-00 and dateto=2009-03-21 i return : ID 2 if the user entered from=2009...

SqlMembershipProvider: use my own database as user store database

Hello. I'm developing an ASP.NET application with Visual Studio 2008 SP1 and C#. I'm also using Sql Server 2008 SP1. I'm trying to add the tables created with the command aspnet_regsql -S (local) -E -A m to my own database. If I run that command it will create a database (Aspnetdb database) with four tables. I want to know if there is...

Have I found an SQL injection bug in SQL server?

So I was playing with my MS SQL Server 2008 app to see how good it is protected against SQL injections. The app lets users to create views in the database. Now consider the following: create view dbo.[]]; drop database foo--] as select 1 as [hi!] This creates a view with a name of ]; drop database foo--. It is valid and you can selec...

Creating MySQL and SQLServer compatible objects

I have a need to support two separate database engines - MySQL and SQL Server. I do not want to maintain two different sets of scripts to create database objects (tables, views, stored procedures etc...), if possible. I wanted to find out if someone has experience in doing such a thing and what were the learnings. Any links to articles/...

Can not call sp_detach_db on a database that is offline

I can run this command in SqlManager to detach the db ALTER DATABASE mydb SET OFFLINE WITH ROLLBACK IMMEDIATE GO dbo.sp_detach_db @dbname = N'mydb',@keepfulltextindexfile = N'false' When I use the same connection running the same commadn via ado.net fails with error: The database 'mydb' can not be opened because it is offline (E...

SQL Server Management Studio Schema View

I'm working with a SQL server and several databases. Each database may have many schema's, such as dbo., admin., other., and I'm getting tired of scrolling around trying to find things. If I'm working on a schema specific project, I want to filter out everything else from my view except that schema. As dbo, I see everything which means ...

SQL Server variables

Why do these queries return different values? The first returns a result set as expected, but the second (which as far as I can tell is exactly the same) does not. Any thoughts? 1: declare @c varchar(200) set @c = 'columnName' select top 1 * from myTable where @c is not null and len(convert(varchar, @c)) > 0 2: SELECT top...

Populate a textfield with the Address of RecordID "101"

I know the following line is not correct. What modifications do I need to make? Thank you! txtAddress.Text = db.ProfileDataset.Tables("tblCustomers").Rows(0).Item("Address").ToString ...

What's the best way to allow queries/views to see how tables looked in the past based on a datetime stamp in SQL Server 2008?

Scenario: We have a great deal of server environmental information (names, IPs, roles, firewall ports, etc.). Currently it's stored in a big Excel workbook on a SharePoint, which trivially allows for side-by-side comparisons of past versions of the data with current, for example. we're planning to move it into a SQL Server 2008 databa...

How to combine two queries as a single result set in SQL for Categories - Subcategories?

I have the following function: CREATE FUNCTION [dbo].[ListStockBySubCategory] ( @CategoryID varchar(10), @SubCategoryID varchar(10), @startRowIndex int, @maximumRows int ) RETURNS TABLE AS RETURN ( SELECT ISBN FROM ( SELECT ISBN, ROW_NUMBER() OVER(AddedDate DESC) AS RowNum FROM ( SELECT DISTINCT RTRIM(...

Sql Server what to do to make collation key from a string value

I receive data files from a source I have no control over (the government) and in the records they have a Company Name field that I actually need to associate with existing company records in my database. I'm concerned that some of the names will vary by minor differences such as 'Company X, Inc.' vs 'Company X Inc'. So my initial thoug...

SQL Server FTS: Ranking is a bit strange

I am using SQL Server 2008's Full Text Search engine in my website. I have a search SP, which shows results sorted based on ranking. I break up the search string and pass it to the FTS query engine like so (search string is 'test search': ("*test*" ~ "*search*") OR ("*test*" OR "*search*"). If the results row has the row 'test search...