Archive for the ‘MS SQL’ Category.
August 22, 2008, 1:09 am
First : DBCC CHECKDB (’DatabaseName’) — this command is list of database errors
Second: DBCC CHECKDB (’DatabaseName’, REPAIR_REBUILD) — if first command is return errors than execute this command. This command is repair successful of database.
Third: DBCC CHECKDB (’DatabaseName’, REPAIR_ALLOW_DATA_LOSS) — if second command is return errors than you may use this command but this command is dangerious because it’s make data loss for minimum damage. Run this command when absolutely create a backup.
August 22, 2008, 12:46 am
Mssql 2005 has provides a lot of encrption function: PassPhrase, synrommetric, asymmetric and encryption by certificate.
PassPhrase function is basicaly method for data encryption. It’s use e user defined decryption key.
Encrypting data by PassPhrase:
Declare @EncryptedData varbinary(MAX)
Select @EncryptedData = EncryptByPassPhrase('cenq', 'mypassword' )
Select @EncryptedData
Decrypting data by PassPhrase:
Declare @DecryptedData nvarchar(36)
Set @DecryptedData = Convert(VarChar(36),DecryptByPassPhrase('cenq', 0x010000000F11B98B5BC8D062F57F404B59C12B0084EF898ABFCC7477F47C99BCF1259C00))
Select @DecryptedData
Output:
mypassword
August 22, 2008, 12:15 am
Unixtime is 32-bit integer. It’s a second counter. A problem is converting datetime to unix time on mssql server. This solution convert unixtime to datetime.
For a more information for Unix Time by wikipedia.
Declare @UnixTime int
Set @UnixTime = 1219366020 -- 08.22.2008 00:47:00
Select dateadd(ss,@UnixTime,'1970-01-01')
To Function:
Create Function fn$UnixTimeToDatetime(@UnixTime int)
Returns Datetime
Begin
Return dateadd(ss,@UnixTime,'1970-01-01')
End
Go
Usage:
Select dbo.fn$UnixTimeToDatetime(1219366020) As DateAndTime