sql-server

Is there a script or program that will efficiently and quickly load up the SO dump into SQL Server?

Before I go about doing this myself, I wonder, has anyone written a script or program that can efficiently and quickly load up the the SO data into SQL Server. I tried the script here but it completely took out my machine. Im thinking either some c# script that streams through the xml file forward only and uses bulk inserter should d...

How to forward demo data dates using a stored procedure?

Hi guys, I am looking for a clean way to forward some demo data using a stored procedure. The data that I want to forward are date types. Due to the nature of my app, some of the data in my app will only appear when certain dates in the data are in the future. I hope this makes sense. : S Since my database is ever expanding, I was thin...

Visual Studio 2008 and SQL Server 2005

I installed VS 2008 and then installed SQL server 2005 and choose desktop tools but Management Studio does not show up. Any ideas? ...

Query all user defined types from Sql Server?

How can I query all user defined data types from sql server like the way I do this for database object which are stored in sysobjects. ...

Group up rows while concatenating a certain column with a delimeter

I have to somehow group up rows while concatenating a certain column, I am not sure how I would go about doing this. The following is an example of what I need. CREATE TABLE People( PersonName varchar(100), PersonAge int ) INSERT INTO People SELECT 'bill', 21 INSERT INTO People SELECT 'harry', 21 INSERT INTO People SELECT 'wesley', 2...

SQL 2005 random connection timeouts / best practice regarding db timeouts

I am using the ADO.Net SqlCommand type and I'm setting the CommandTimeout to 30 seconds. My problem is that the connection/command keeps timing out causing unhandled exceptions that crash my system! The data I am trying to retrieve is critical to the system – so I want to fix the timeouts rather than add exception handling retry logic....

T-SQL Time Averaging

I have a table in SQL Server that stores statistics for a piece of hardware, rows in the table represent data for a given second. It contains for example, these columns: timestamp (DateTime) value (int) What I want to do is select the data from the table for a given date/time range but return it in such a way that it averages for a gi...

Database Structure viewer/printing

I have an SQL Server database, with over 60 tables in it. This database has plenty of relationships between these tables and while it's normalized, it's still complex to use because of the huge number of tables. There are, of course, many tools that can show the database structure in some diagram. SQL Server itself is even able to creat...

How do I cast Scope_Identity() to Int?

So Scope_Identity() returns an ?-Byte Numeric Type in SQL Server. That is not awesome. Is there a safe way to cast it to an int in a select query so we don't have to manage every whim of SQL Server in our ODBC Wrapper? ...

SQL Server Bulk Insert

I want to import a one column text file into one of my sql tables. The file is just a list of swear words. I've written the following TSQL to do this BULK INSERT SwearWords FROM 'c:\swears.txt' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) However it errors with unexapected end of file. The table im importing to is just an id...

Advice on how to scale and improve execution times of a "pivot-based query" on a billion rows table, increasing one million a day.

Our company is developing an internal project to parse text files. Those text files are composed of metadata which is extracted using regular expresions. Ten computers are 24/7 parsing the text files and feeding a high-end Intel Xeon SQL Server 2005 database with the extracted metadata. The simplified database schema looks like this: ...

Group by with count

Say I have a table like this in my MsSql server 2005 server Apples + Id + Brand + HasWorms Now I want an overview of the number of apples that have worms in them per brand. Actually even better would be a list of all the apple brands with a flag if they are unspoiled or not. So if I had the data ID| Brand | HasWorms ------...

Will uninstalling a named instance of SQL Server require a reboot or cause issues with existing instances?

I have a server with a default instance and 2 named instances of SQL Server 2005 standard installed. This is a mission critical production server that cannot be restarted during normal business hours. Will uninstalling the two named instances of SQL Server 2005 require a reboot or put the server in a state that may cause issues with th...

sp_tableoption in SQL Server

Hello everyone, I want to know and pros and cons of setting sp_tableoption of "table lock on bulk load" for SQL Server 2005/2008? My scenario is, I have 3 threads working on database, one query thread, one bulk insert thread and one delete thread. Here is the MSDN related link for sp_tableoption, http://msdn.microsoft.com/en-us/librar...

Help me Fix this SQL Statement?

Can someone let me know what is wrong with my SQL Statement and how I can improve it? da = new SqlDataAdapter("SELECT * FROM Guests"+" WHERE Students.name='" + byNametextBox.Text + "'", MyConn); ...

How should I test a field against an SQL variable which can be null ?

I've got the following SQL : CREATE TABLE tbFoo( a varchar(50) NULL, ) CREATE NONCLUSTERED INDEX IX_tbFoo_a ON tbFoo ( a ASC ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) insert into tbFoo ...

how to use an mdf in App_Data with shared hosting

If I create a website that uses an mdf in App_Data with the connection string: Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes; what do I need to do to run the site in a shared hosting environment? Do I need to copy the contents of my mdf to the main SQL Server engine of my ...

SQL Server - Include NULL using UNPIVOT

UNPIVOT will not return NULLs, but I need them in a comparison query. I am trying to avoid using ISNULL the following example (Because in the real sql there are over 100 fields.: Select ID, theValue, column_name From (select ID, ISNULL(CAST([TheColumnToCompare] AS VarChar(1000)), '') as TheColumnToCompare from MyView where The_...

SQL CASE vs JOIN efficiency

In my MS SQL Server database I am pulling transaction data based on a variety of different codes that are in one column. Would it be more efficient to: join the same table over and over for each code in a WHERE clause do multiple case statements on the whole table (shown below) do multiple case statements on the whole table but limit ...

Visual Studio 2008 Debugging of SQL Server 2005 SP on Remote Host

I am using VS 2008 and trying to step into a stored procedure on a SQL Server 2005 database. I bring up Server Explorer, double-click on the procedure. It comes up in the text window. I set a break point in it, right click and select "Step into stored procedure". It comes back with "canceled by user". MSVSCOM.exe is running on the SQL Se...