sql-server

How do I (quickly) collate IDs from various tables?

I have three denormalized tables that I have to take at face value (data comes from some external resource). The three tables have different definitions, but they each describe the same object from different perspectives. object1 A B object2 A object3 B C object4 C The only commonality between these tables i...

Generate SQL Create Scripts with Query

I need to be able to get the CREATE scripts for existing tables within SQL Server 2008. I assume I can do this by querying the sys.tables somehow, however this isn't returning me the CREATE script data. ...

What is the Auto-Close option when creating a new database in SQL Server 2008?

What is the Auto-Close option when creating a new database in SQL Server 2008? EDIT: and how do you decide whether to turn it on or off? ...

Linq To Sql - Update not being persisted.

I am really confused about why an update is not taking place. This is very simple: int goodID = 100; DataContext db = new DataContext(); Schedule schedule = db.Schedules.Single(s => s.ID == goodID); // this wont persist - WHY NOT?! schedule.Email = txtEmail.Text; // this does persist schedule.NumberCourse...

SQL Server - Grid Result Save As .CSV - How to output Text instead of UTF-16 (Unicode)

Can SQL Server Grid "Save As" be changed to write out an encoding that is Text instead of UTF-16? When I right click a Result Grid in SQL Server it allows for a Save As .CSV. Currently it saves the .CSV file encoded as UTF-16 (Unicode) but Excel does not open this format automatically (Excel prompts for a delimiter). To get around the p...

How do I write an SQL query which looks for a value in all columns and all tables in my database?

Hello. I'm trying to look for a value in my Microsoft SQL Server 2008 database but I don't know what column or table to look in. I'm trying to craft a query which will just look in all tables and all columns for my value. ...

Indexing in Sql Server

What is Clustured and non clustured indexing? How to index a table using sql server 2000 Enterprise manager? thanks in advance for your kind reply.. ...

Mutex Stored Procedure

Hi All, I want to create some distributed mutual exclusion using a database table. It would be nice to have the following interface on a stored procedure: Wait(uniqueidentifier) I was originally thinking of implementing this by having a table of unique identifiers. A call to the procedure would wait until the unique identifier does no...

Difference between CTE and SubQuery?

From this post How to use ROW_NUMBER in the following procedure? There are two versions of answers where one uses a SubQuery and the other uses a CTE to solve the same problem. Now then, what is the advantage of using a CTE (Common Table Expression) over a sub-query(thus, more readable what the query is actually doing) The only advant...

How would a SQL Server 2005 database lose a few days data?

Hi! I really need some help here. I'm the owner of a SQL Server Database application that lost three days data! I can't understand how or why. So here is the set-up. SQL Server 2005 32bit standard edition database on Windows 2000 server. (Database B) Database is in simple recovery mode The database is connected as a subscriber to ...

Lost ability to be admin on SQL Server Reporting Services 2005

I used to be able to go to http://myserver/reports and after I supplied my local account information (which was a member of "Administrators"), I would get the "Home" page of SQL Server Reporting Services along with the "Site Settings" link at the top right. Now, when I login, that's gone and it seems I'm just a "regular user" because th...

Sql 2008 "Public Not Granted Server Permission" policy

I recently started looking into the new Policy Management in SQL Server 2008 and when I checked for compliance with the "Public Not Granted Server Permission" policy, my server failed the check. The reason was, and I am pretty sure this is the default, public has TCP Endpoint permission so that users can connect to the server. If I wer...

Quick way to backup SQL SP and Functions?

I have a long list of SPs (stored procedure) and Functions in my SQL server db. I could save them one by one by right clicking and script XXX to Alter To. Is there any way in TSQL to query all SPs and functions save them to xxx.sql files? For example, for sp_mySP1, I would like to save it to sp_mySP1.sql which is a text file. The databa...

T-SQL Cast versus Convert

What is the general guidance on when you should use CAST versus CONVERT? Is there any performance issues related to choosing one versus the other? Is one closer to ANSI-SQL? ...

What is the difference between Shrink and Compact in SQL Server CE?

I have a method that is run periodically to optimise my application's SQL Server Compact Edition (3.5) database. The existing code uses the Shrink() method: SqlCeEngine engine = new SqlCeEngine(dbConnectionString); engine.Shrink(); Today I noticed that there's also a Compact() method. Which is preferable for periodic m...

Company-Employee database design

I am trying to build a SQL 2005 database that has a Company data table and an Employee data table. Each company should have an Employee 1, Employee 2, and so on. I realize that each Employee record would have a PK of both their EmployeeID and their CompanyID, but I haven't for the life of me determined the best way of doing this? An...

Help with sql server trigger

Hi, I want to create a trigger that will update the column LastActivityDate to the current date when the Description column is updated, the problem is that all the rows are being updated, and I don't know how to make the where clause inside the trigger... I need to make a trigger like this for other tables as well, like the Votes table....

Create NEW database from Snapshot (SQL Server 2005)

I'm using SQL Server 2005. I've created a snapshot of database (RM_DB), I want to create (RM_DB_NEW) from that snapshot. The only option i get when I right-click on my snapshot is "Restore [RM_DB] from this snapshot". Can I create a NEW database from my snapshot? EDIT I'm not interested in creating a backup out of the snapshot, this w...

Unicode Collations problem ?

(.NET 3.5 SP1, VS 2008, VB.NET, MSSQL Server 2008) I'm writing a small web app to test the Khmer Unicode and Lao Unicode. I have a table that store text in Khmer Unicode with the following structure : [t_id] [int] IDENTITY(1,1) NOT NULL [t_chid] [int] NOT NULL [t_vn] [int] NOT NULL [t_v] [nvarchar](max) NOT NULL I can use Linq to SQL...

SQL Server to Oracle?

How do you convert SQL Server table and procedures to Oracle? ...