MSSQL
Shrink / Delete a SQL Server Log File
Submitted by TimBruce on Wed, 2010-01-27 13:03When you want to delete a transaction log file (when you have more than one), you need to do the following steps:
ALTER DATABASE dbname SET RECOVERY SIMPLE
ALTER DATABASE dbname SET RECOVERY FULL
or
USE TimsDatabase
BACKUP LOG FileName WITH TRUNCATE_ONLY
GO
DBCC SHRINKFILE ( 'TimsDB_log1' )
GO
DBCC SHRINKFILE ( 'TimsDB_log2' )
GO
Table Size in Microsoft SQL Server
Submitted by TimBruce on Wed, 2010-01-27 13:02Sometimes I want to find out how many rows are in each user table in a SQL Server 2000 database. The following SQL helps me determine this.
select
'SELECT COUNT(*) AS ' ''' +
RTRIM ( name ) + '''' +
' FROM ' + RTRIM ( name )
from
sysobjects
where
type = 'U'
order by
name
SQL Server Permissions
Submitted by TimBruce on Wed, 2009-06-03 20:25Installation of Microsoft SQL Server requires that it have certain permissions in order to run on the local system. Some people choose to have it run under a Domain Account that has Administrative Access. And at one point (especially SQL Server v6.5 and SQL Server v7.0) it was much easier to install if you used an Acount that had Administrative access (i.e., Local Administrator Group role). I even believed at one point that using a Domain account made it easier for SQL Agent jobs to export data to remote file shares.
SQL Server Version
Submitted by TimBruce on Thu, 2008-09-04 20:32There are a variety of ways to determine which version of SQL Server you are running. While the @@version information will tell you the current version
SELECT @@version
SELECT LTRIM(RIGHT(LEFT(@@VERSION,38),9))
The following code will as well, and in a slightly different format:
SELECT 'SQL Server '
Listing Active Users in Microsoft SQL Server
Submitted by TimBruce on Fri, 2006-05-12 18:58Sometimes you want to be able to list the active users, and you can use the system stored procedures of sp_who and sp_who2 to do that. However, I've found that it's inconvenient for a couple of reasons.
1. If you run it from a command line, it scrolls over the 80 column limit you usually have in a terminal session (sometimes I run this using a command like osql -E -S sql -Q 'exec master..usp_ListUsers'). While this also goes over the 80 column limit, it goes over 2 lines, so it's more readable to me.
