Recover sa password [closed]

The best way is to simply reset the password by connecting with a domain/local admin (so you may need help from your system administrators), but this only works if SQL Server was set up to allow local admins (these are now left off the default admin group during setup). If you can’t use this or … Read more

Why does SQL Server @@SERVERNAME return my old machine name?

This is well known and documented, see Rename a Computer that Hosts a Stand-Alone Instance of SQL Server: When you change the name of the computer that is running SQL Server, the new name is recognized during SQL Server startup. You do not have to run Setup again to reset the computer name. Instead, use … Read more

fastest way to export blobs from table into individual files

I tried using a CLR function and it was more than twice as fast as BCP. Here’s my code. Original Method: SET @bcpCommand = ‘bcp “SELECT blobcolumn FROM blobtable WHERE ID = ‘ + CAST(@FileID AS VARCHAR(20)) + ‘” queryout “‘ + @FileName + ‘” -T -c’ EXEC master..xp_cmdshell @bcpCommand CLR Method: declare @file varbinary(max) … Read more

How to remove white space characters from a string in SQL Server

Using ASCII(RIGHT(ProductAlternateKey, 1)) you can see that the right most character in row 2 is a Line Feed or Ascii Character 10. This can not be removed using the standard LTrim RTrim functions. You could however use (REPLACE(ProductAlternateKey, CHAR(10), ”) You may also want to account for carriage returns and tabs. These three (Line feeds, … Read more

How to run the same query on all the databases on an instance?

Try this one – SET NOCOUNT ON; IF OBJECT_ID (N’tempdb.dbo.#temp’) IS NOT NULL DROP TABLE #temp CREATE TABLE #temp ( [COUNT] INT , DB VARCHAR(50) ) DECLARE @TableName NVARCHAR(50) SELECT @TableName=”[dbo].[CUSTOMERS]” DECLARE @SQL NVARCHAR(MAX) SELECT @SQL = STUFF(( SELECT CHAR(13) + ‘SELECT ‘ + QUOTENAME(name, ””) + ‘, COUNT(1) FROM ‘ + QUOTENAME(name) + ‘.’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)