Category Archives: SQL

Recover database in “Restoring…” mode

Here is the sql to run when your database is in restoring mode. restore database Budgets with recovery You should know why your database is in restoring mode to begin with before running. For me, it’s typically because I left … Continue reading

Posted in SQL | Leave a comment

Approximate total rows in SQL Server database

Here is a script that approximates the total rows in your SQL Server 2005+ database. It’s approximate because it comes off sys tables which are not updated constantly. SELECT [TableName] = so.name, [RowCount] = MAX(si.rows) FROM sysobjects so, sysindexes si … Continue reading

Posted in SQL | Tagged | Leave a comment

Alias names in LINQ

Finally figured out how to set alias names in LINQ, and it’s easy. Dim orgs = From p In db.Departments Select p.deporg, Name = p.deporg & " – " & p.depname Order By deporg Name being the name of the … Continue reading

Posted in SQL, VB.NET, Visual Basic | Tagged | Leave a comment

How to copy a table in SQL Server

For some reason I keep forgetting the syntax SELECT * INTO MyNewTable FROM MyTable

Posted in Programming, SQL | Tagged , | Leave a comment