sql-server

does it makes sense to use int instead of char or nvarchar for a discriminator column if I'm using it as FK also

I have something like this: create table account ( id int identity(1,1) primary key, usertype char(1) check(usertype in ('a', 'b')) not null, unique(id, usertype) ) create table auser ( id int primary key, usertype char(1) check(usertype = 'a') not null, foreign key (id, u...

Consolidate data from many different databases into one with minimum latency

I have 12 databases totaling roughly 1.0TB, each on a different physical server running SQL 2005 Enterprise - all with the same exact schema. I need to offload this data into a separate single database so that we can use for other purposes (reporting, web services, ect) with a maximum of 1 hour latency. It should also be noted that thes...

sql server change PK type from int to uniqueidentifier

Hi! I need to change the type of my primary key column on a table from int to guid. The database already has data that I don't want to lose, and there are foreign keys to consider. Is there a painless way to do this or do I have to manually do it through a big a** script?:) I would appreciate any suggestions ...

SQL efficiency argument, add a column or solvable by query?

I am a recent college graduate and a new hire for software development. Things have been a little slow lately so I was given a db task. My db skills are limited to pet projects with Rails and Django. So, I was a little surprised with my latest task. I have been asked by my manager to subclass Person with a 'Parent' table and add a refer...

choosing row (from group) with max value in a SQL Server Database

I have a large database and am putting together a report of the data. I have aggregated and summed the data from many tables to get two tables that look like the following. id | code | value id | code | value 13 | AA | 0.5 13 | AC | 2.0 13 | AB | 1.0 14 | AB | 1.5 14 | AA | 2.0 13 | A...

Disable TSQL script check?

Hi, lets say I have a script like that: if(some condition) begin select somecolumn from sometable end Lets say, that "somecolumn" does not exist and the condition is not true, which means the select is NOT executed. Even though the select would not be executed, the script is not valid, Management Studio complains about the missing ...

Calculating monthly reports or statistics - MVC Entity Framework LinQ

Hi I am using MVC (C#) and the Entity Framework. I have a sql server database with tables called Profile, Gallery, ArtWork : PROFILE: UserName, FirstName, etc... GALLERY: GalleryID, UserName, GalleryName, ARTWORK: ImageGuid, GalleryID, Description, PublishDate, Views, Downloads, I have the following relationship between the tables: ...

SSRS sum(distinct()) equivalent

I am currently working with an SSRS 2008 report that returns a dataset similar to the following: Job# ClientId MoneyIn MoneyOut ------------------------------ 1 ABC123 10 25 1 ABC123 10 25 1 ABC123 5 25 2 XYZ123 25 50 2 XYZ123 25 50 3 XYZ123 15 15 Where MoneyOut shoul...

Recursive Query Help

I have two tables in my database schema that represent an entity having a many-to-many relationship with itself. Role --------------------- +RoleID +Name RoleHasChildRole --------------------- +ParentRoleID +ChildRoleID Essentially, I need to to be able to write a query such that: Given a set of roles, return the unique set o...

How to manage and capture database changes across several developers?

We have three developers and one tester all working against the same database. We change the schema of the database quite often, and every time we do it tends to have a ripple effect of headaches for everyone else. Are there good practices in place for .NET oriented development against MS SQL Server 2008 for managing this? I am thinkin...

List all tables that are currently published for replication MS-SQL

I need to get a list of all tables that are published for replication from MS-SQL 2005/2008 databases. Is there a system stored procedure or a query I could run to generate such a list? Thank you, ...

Best method for seeing if SQL Server 2000 processes are running?

We have an old SQL Server 2000 machine where a bunch of jobs run overnight. Occasionally, after server maintenance is performed and the machine is rebooted, some SQL components don't come up with the OS (even though they are configured to do so). So before our nightly jobs are supposed to run, I would like to (from a remote machine) run ...

Row as XML in SP

From SP i need to get a row as as XML (Includeing all fileds.) Is there any way we can get like below. Declare @xmlMsg varchar(4000) select * into #tempTable from dbo.order for xml raw select @xmlMsg = 1 from #tempTable print '@xmlMsg' + @xmlMsg Row i would like to get it as XML output. ...

SQL Server and .NET Typed Dataset AllowDBNull Metadata

Good afternoon, I am generating a typed dataset from a stored procedure. The stored procedure may contain something like: select t1.colA, t2.colA AS t2colA from t1 inner join t2 on t1.key = t2.key When I generate the typed dataset, the dataset knows whether t1.colA allows NULLs, but it always puts FALSE in AllowDBNull for ...

hundreds of databases sql server log shipping

SQL Server 2005 Standard 64x, with 300+ tiny databases currently (5MB each), user base adds databases as needed. Want to implement log shipping for warm standby, but not via the wizard, since that looks like it adds 3 jobs (1 on primary, 2 on secondary) for each log-shipped database. Do I try to write my own or use something like Quest...

SQL Server Reporting Services Bar Chart

I am trying to create horizontal bar chart to look like a pill chart. I would like to take a either a stacked bar chart or a 100% stacked bar chart and put rounded ends onto this chart. I would only be using 1 row within the chart. One idea I had was just putting rounded images on either end of the chart to accomplish this but I'm n...

SSRS Report Server with Forms Auth Not Working on a Port other than 80

Hello, We setup a custom implementation of an SSRS report server to use forms authentication. Can we use a port other than 80? We are getting 401 unauthorized when we do use another port other than port 80. Any ideas? Thanks. ...

How to count each record in each table in a SQL Server 2005 Database?

I need to know how many records are in each table in a particular database. I don't care what is in the record, they will all need to be counted. I already know how to do this for a single table as SELECT Count(1) FROM [my_table_name], but this gets a little redundant for 200+ tables. ...

Upgrading From Sql Server 2005 to Sql Server 2008

Our company wants to upgrade from Sql Server 2005 to Sql Server 2008 and I wanna ask about: What are the steps I should follow to upgrade from 2005 to 2008 ? At what point should I take care of it while upgrading ? ...

When are SQL views appropriate in ASP.net MVC?

I've got a table called Protocol, a table called Eligibility, and a Protocol_Eligibilty table that maps the two together (a many to many relationship). If I wanted to make a perfect copy of an entry in the Protocol table, and create all the needed mappings in the Protocol_Eligibility table, would using an SQL view be helpful, from a perf...