sql-server

Can I run DBCC CHECKDB from .NET?

I am writing a scheduled job to mimic a SQL Server maintenance plan for SQL Express. (I have to do this because SQL Agent and related tools don't exist for SQL Express) One of the steps is to do a database integrity check. The TSQL for this is: DBCC CHECKDB(N'Northwind') WITH NO_INFOMSGS How do I know if an error occurred during ex...

Select million+ records while huge insert is running

I am trying to extract application log file from a single table. The select query statement is pretty straightforward. select top 200000 * from dbo.transactionlog where rowid>7 and rowid <700000 and Project='AmWINS' The query time for above select is above 5 mins. Is it considered long? While the select is running, the bulk insert...

RESTRICTED_USER

Before changing database schema I issue: ALTER DATABASE SET RESTRICTED_USER On completion: ALTER DATABASE SET MULTI_USER I understand that a running transaction will be permitted to continue until completion. Q: Is there any way to wait till all regular users are off the database? Q: Can the regular users issue more transactions?...

When would you use GUIDs as primary keys?

Possible Duplicate: Advantages and disadvantages of GUID / UUID database keys Are there any circumstances where it is essential to use GUIDs as primary keys in a SQL Server 2005/8 DB. For example, does the use of the MS Sync Framework force this, or data replication? ...

SQL Server Analysis Services 2008 and ByAccount Aggregations

Hi I am having problems getting the 'ByAccount' aggregation to work in SQL Server Analysis Services (SSAS) 2008. I am trying to create a financial reporting solution, with Balance Sheet and Profit and Loss elements. I have a fact table with figures at a month level of granularity. There is one measure I am interested in on this table ...

Performance of non-numeric indexes

If I use a nvarchar(n) column as a clustered index on a SQL Server database, am I going to suffer a significant performance hit compared to a numeric (int) index? Also how does the performance of compound indexes compare? ...

Stored Procedure Maintenance

In sql server ... Should I maintain stored procedures via the object broswer in query analyzer, or as external text files and why? ...

COBOL to SQL Server

Hello, Can anyone point me at a way to talk to SQL Server from Fujitsu COBOL? Event talking to COM / ActiveX would be a start. Many Thanks Neil ...

Does Microsoft's SQL Server Database Publishing Wizard work with SQL Server 2003

Does Microsoft's SQL Server Database Publishing Wizard work with SQL Server 2003? Just wondering because all I can find info about is 200 or 2005. ...

How did my database security fail?

In a couple of my tables in my SQL Server 2005 database all of my data has been erased. Is there anyway to get a log in SQL Server of all the statements that have ran in the past day? I am trying to find out if someone did this on accident, there is a vulnerability in my web app, or the actual DB has been compromised. ...

How to disable SQL Server Management Studio for a user

Is there a way to prevent users from getting into SQL Server Management Studio so that they can't just edit table rows manually? They still need to access the tables by running my application. ...

Does SQL Server SMO require special permissions to be used?

I have SMO code which copies tables from one database to another. It runs fine in a desktop app. The same exact code put in a service, gives an error. The error is really obscure and doesn't hint about permissions. I was wondering if the SMO objects need any kind of security to be used. Security context? Windows credentials.. etc? I am ...

PDO - SQL Server RESTORE DATABASE query - wait until finished?

I am using PDO to restore a SQL Server 2008 database, and issuing a query to restore the database like this: $pdo->exec('RESTORE DATABASE [blah] FROM DISK = \'c:\blah.bak\' WITH NOUNLOAD'); But the exec() returns before the database is fully restored, is there any way I can make it wait? If not, is there a query I can run in a loop wi...

SQL 2008 as a xml document database

Has any one used SQL server 2008 as an xml document database? what are you thoughts on doing so. Is the indexing and querying of the XML data type suficent to support this type of role? Is the query performance of XML acceptable? ...

Insert value from one table to another by changing the flag

I have to insert value from one table to another table which both having two fields first field name is ID and and second field name is Flag. While inserting if the ID value already exists in any of the destination table rows it will insert the new row in source table as same ID and Flag as NEW if the ID value is not matching in any of...

How can I import and export data from SQL Server 2005 to XML format?

I am very confused about how SQL Server 2005 supports importing and exporting of XML files. I was thinking that BCP was the way to go. However after reading all of the documentation it seems like there is no way to just take a regular table and export it in XML format. The reason that I am asking is that I am working with a client tha...

How to select columns from table in random order in TSQL

I have a table with 5 columns in it, what's the easiest way to select all rows, but where each column is individually randomised? All I can think of is to select each column separately, along with row_number over ( order by newid()) as lookup and then join each column back together on lookup. Is there an easier way? Thanks ...

Good table editor for MS SQL Server?

I have MS SQL Management Studio for editing table data, and it is doesn't have a good usability. I need to edit some hundred rows like in Excel, being able to order columns to easy editing process (SQL Mgmt only has 'Open table' feature, without ordering columns, updates diferent than that is only possible using UPDATE SQL code). LinqPa...

How to implement automatic timestamps for record changes (SQL Server)

I am used to using "changed_at" fields in my MySQL database that Ruby on Rails automatically updates when changing a record. Now I am using ASP.NET MVC with SQL Server 2008 and I am wondering, how would I proceed to get the same functionality. Does SQL Server have an option for auto updating a field when updating? ...

Select values from XML field in SQL Server 2008

Just looking at my XML field, my rows look like this: <person><firstName>Jon</firstName><lastName>Johnson</lastName></person> <person><firstName>Kathy</firstName><lastName>Carter</lastName></person> <person><firstName>Bob</firstName><lastName>Burns</lastName></person> Note that these are three rows in my table. I'd like to return a S...