sql-server

SQL Server Express 2008 not detaching auto-attached file?

The MSDN documentation for SQLEXPRESS says: When an application first establishes a connection from a running instance of SQL Server Express, SQL Server Express will automatically attach an .mdf file. When the user closes the application, SQL Server Express detaches the .mdf file from the instance. This does not appear to be happe...

Setting a default value for a stored proc select statement

I am creating a stored proc that selects a value from a table and uses it in another procedure. If the first value that is searched doesn’t exist I need it to use a default value. I’m new to stored procs so I’m not sure of the best practices. Here is the first select statement which may or may not return a value. If it doesn’t return a ...

strategy to filter data according to user access level

we currently have a very simple security schema... we have resources, that roughly maps to tables, we have access to that resources (add, modify, delete, query) and we have groups. each permission consists of a resource, with a specified access and a group and each user can belong to many groups... so, permission is a many-to-many be...

Basic Datatypes in SQL Server?

What should i know about involving basic data types in SQL Server? In my database i need Flags/bits, I assume I should use byte 64bit ids/ints a variable length string. It could be 5 letters it could be 10,000 (for desc but i plan to allow unlimited length usernames) Is there a TEXT type in SQL Server? I dont want to use varchar(...

What should i know about switching from sqlite to SQL Server

Currently i have no way to test my code with SQL Server. I know nothing about it and have been using SQLite. What should i know while switching? My app is programmed in C# .NET ...

How to Download A file stored in SQL DB in Binary Format

Hi, I am simply storing uploaded file into a binary field in SQL Server but I also need to allow users to download it with Asp.NET. How can I do that ? Thanks in advance. ...

Database structure of multi-lingual site

I need database structure for storing versions of site's content in different languages. Right now I'm doing it like this: [Item] Id SomeColumn [ItemStrings] ItemId LanguageId Title Description ... [Languages] Id Culture Although, it is a pretty neat way to do translation, it requires a lot of monkey coding when ...

Practical limits of SQL-Server database.

I am setting up a database that I anticipate will be quite large, used for calculations and data storage. It will be one table with maybe 10 fields, containing one primary key and two foreign keys to itself. I anticipate there will be about a billion records added daily. Each record should be quite small, and I will primarily be doing i...

Combining two T-SQL pivot queries in one

Suppose you had this table: CREATE TABLE Records ( RecordId int IDENTITY(1,1) NOT NULL, CreateDate datetime NOT NULL, IsSpecial bit NOT NULL CONSTRAINT PK_Records PRIMARY KEY(RecordId) ) Now a report needs to be created where the total records and the total special records are br...

Reproducible Deadlock Using Cascading Constraints

I am looking for code to generate a reproducible deadlock that occurs from the use of Cascading Constraints. I can find references online for the specific problem, and I have answered dozens of questions on deadlocks where cascading constraints were in use, but none of them has a reproducible version of the deadlock. I am not looking fo...

How can I alter a smalldatetime column with a default to be datetime?

I have a number of columns in my database that were originally created as smalldatetime and that really need to be datetime. Many of these columns were created with the DDL: [columnname] smalldatetime not null default getdate() ...which means that in order to alter the column's type, I first have to drop the default, and then re-crea...

What determines which local SQL Server cache tables can be cached?

I have a c# Visual Studio app. I connected to an existing SQL Server 2008 database and the Studio created a local cache (.sdf file) for me, caching all existing tables. Now I added 2 additional tables the the SQL Server database and want to update my DataSet with these, but the wizard does not allow me to select the new tables as being ...

What is an easy way to read a sql server table into a hash in Perl?

I'd like a simple perl script / sub to read a sql server table into a hash, does anyone have a good script or snippet (with 'use's) that can do this given a connection string and table name? Here's a template: sub sqltable { my ($connStr,$table) = @_; my ($user, $password, $host) = ($connectstr =~ m|^(.*)/(.*)@(.*)$|); ...

SQL Server Latches and their indication of performance issues

I am trying to understand a potential performance issue with our database (SQL 2008) and in particular one performance counter, SQLServer:Latches\Total Latch Wait Time Total Latch Wait Time (ms). We are seeing a slow down in DB response times and the only correlating spike that I can match it with is a spike in Total Latch Wait Time and ...

Stored Procedure WHERE LIKE ID or NAME

Group, I am trying to create a stored procedure using one variable @Customer. What I want to do is put something in my WHERE clause that says if it is a number search the CustomerID field where the number entered is LIKE CustomerID... If a char is entered search the CustomerName field where the text entered is LIKE CustomerName. Below ...

How can I include an ALTER VIEW statement in a transaction for a deploy script?

I'm running SQL Server 2005 on prod, but developing on 2008, and I need to alter a view to add a column. However I'm having trouble creating the deploy script because I need to wrap it in a transaction like this begin tran; alter view [dbo].[v_ViewName] with schemabinding as select ... /* do other stuff */ commit; When I do ...

SQL: Datatype choice for values -1, 0 and 1

Consider a table whose job is to store a rating of an object. The column of interest here is the one called RATING. The valid range of values to store is: 1 0 -1 The first thought was to store as a tinyint smallint. This would store only one byte two bytes per row. Given the tinyint's range of 0 to 255 smallint's range of -32768 to 3...

SSRS - Unable to determine if the owner of job has server access [SQLSTATE 42000] (Error 15404))

SQL Server Reporting Services, in SSRS it seems like Schedules never fire, however a look at the SQL Agent reveals a permission issue related to not being able to resolve a user account. Seems SQL Agent does not rely on caching or whatever voodoo Windows magically works. link text Fix is listed here... edit -- Above is the fix I used...

Date of last login or read operation on a SQL Server database?

Lets say I have a SQL Server with 100 databases on it. How can I find out which ones are actually being used? (without turning them all off and waiting for the complaints to come in) So 'have been accessed in the last week' or something like that. I've tried the data file dates but they don't seem to represent that and databases do no...

Free comment reply system like intensedebate?

Is there any free script in PHP/MYSQL or in ASP.NET/SQL Server for comment reply system like intensedebate.com. In intensedebate we can reply to any comment or reply. I need the similar free script which I can modify according to my website needs. Please let me know if anybody knows any system like this or if anyone has some concept whi...