Posts Tagged ‘SQL Server’

With every new version of SQL server, Microsoft is adding new and exciting features for database encryption. In SQL Server 2008, Microsoft has introduced a new encryption technique called Transparent Data Encryption (TDE). With TDE, Encryption is performed on the database with real time I/O operations. The performance of encryption and decryption is better when compared to SQL Server 2005.

Transparent Data Encryption (TDE) uses database encryption symmetric key (DEK) for the purpose of encryption and decryption. DEK is stored in master databased secured by certificate or asymmetric key. TDE provides the ability to encrypt the data at root levels meaning data and log files. This way users can encrypt the data without modifying the design of existing applications. TDE does not affect the size of the database. Size of the database remains same with or without TDE encryption. for TDE enabled database, backup files are also encrypted using DEK. So, during the restore process, certificate protecting database must be available. Care must be taken to backup server certificates on regular basis.

Following are the important steps in configuring the Transparent Data Encryption (TDE).

  1. Create a Master Key
  2. Generate a certificateprotected by master key.
  3. Create a database encryption key (DEK) protected by certificate.
  4. Enable the TDE encryption for selected database.

Here is an example for enabling the encryption on database Northwind using a certificate named MySQLCertificate.

USE Master;
GO
 
--Create Master Key
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Password1';
GO
 
--Create Certificate
CREATE CERTIFICATE MySQLServerCertificate WITH SUBJECT = 'My SQL Server Certificate'
GO
 
USE Northwind
GO
 
--Create Database Encryption Key (DEK)
CREATE DATABASE ENCRYPTION KEY
WITH ALGORITHM = TRIPLE_DES
ENCRYPTION BY SERVER CERTIFICATE MySQLServerCertificate
GO
 
-- Enable the TDE Encryption for the database
ALTER DATABASE Northwind
SET ENCRYPTION ON
GO
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • HackerNews
  • Slashdot
  • StumbleUpon
  • TwitThis
  • Yahoo! Buzz
  • Tumblr
  • Share/Bookmark

Tags: , , ,

4
May

Check database size on SQL Server using Excel Macro

   Posted by: Rasik Jain    in Programming

Following is a script to check the size of each database in a server. It checks the Database size, DBFile size and Log file size. Below code loops through all the databases on the selected server and exports the information to the Excel sheet.

 
'Declare Variables for Server name, Database, DB File, Log File etc
Dim vServerName
Dim objServer
Dim objDatabase
Dim objDBFile
Dim objLogFile
Dim xlApp
Dim xlBook
Dim xlSheet
Dim Row
Dim Cell
 
' Messagebox for server name
vServerName = InputBox("Please Enter Server Name:","Server Name","(local)")
If vServerName = "" Then
vServerName = "(local)"
End If
 
'Create Excel Object
Set xlApp = CreateObject("Excel.Application")
 
'Add Workbook to Excel Obj
Set xlBook = xlApp.Workbooks.Add
 
'Add Sheet to WorkBook
Set xlSheet = xlBook.Worksheets.Add
 
'Make Visibility for Excel App
xlSheet.Application.Visible = True
 
' Set column headers
xlSheet.Cells(1, 1) = "Database Name"
xlSheet.Cells(1, 2) = "Space used (MB)"
xlSheet.Cells(1, 3) = "Space Available (MB)"
xlSheet.Cells(1, 4) = "DBFile (MB)"
xlSheet.Cells(1, 5) = "LogFile (MB)"
Row = 2
 
xlSheet.Rows("1:1").Font.Bold = True
xlSheet.Range("B:E").HorizontalAlignment = -4152
 
' Create the server object using SQL-DMO
Set objServer = CreateObject("SQLDMO.SQLServer2")
 
'Set Authentication for Server
' Login with current Windows account
objServer.LoginSecure = True
objServer.Connect vServerName
 
 
'Loop through all the databases and get the properties of databases
For each objDatabase in objServer.Databases
 
SET objDBFile = objDatabase.Filegroups("PRIMARY").DBFiles(1)
SET objLogFile = objDatabase.TransactionLog.LogFiles(1)
xlSheet.Cells(Row, 1).Value = objDatabase.Name
xlSheet.Cells(Row, 2).Value = objDatabase.Size
xlSheet.Cells(Row, 3).Value = Round(objDatabase.SpaceAvailableInMB,3)
xlSheet.Cells(Row, 4).Value = objDBFile.size
xlSheet.Cells(Row, 5).Value = objLogFile.size
 
Row = Row + 1
Set objDBFile = Nothing
Set objLogFile = Nothing
Next
 
xlSheet.Cells.EntireColumn.AutoFit
 
 
'Save our changes
xlBook.SaveAs ("C:\DBSpaceUsage.xls")
xlBook.Close
 
MsgBox "Check the file at C:\DBSpaceUsage.xls"
 
' Clean up memory
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
set objDatabase = Nothing
Set objServer = Nothing
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • HackerNews
  • Slashdot
  • StumbleUpon
  • TwitThis
  • Yahoo! Buzz
  • Tumblr
  • Share/Bookmark

Tags: , ,