Showing posts with label SQL Queries. Show all posts
Showing posts with label SQL Queries. Show all posts

Monday, May 30, 2016

SQL Server Insert if not exist

SQL Server Insert if not exist
BEGIN
   INSERT INTO EmailsRecebidos (De, Assunto, Data)
   VALUES (@_DE, @_ASSUNTO, @_DATA)
   WHERE NOT EXISTS ( SELECT * FROM EmailsRecebidos 
                   WHERE De = @_DE
                   AND Assunto = @_ASSUNTO
                   AND Data = @_DATA);
END
replace with
BEGIN
   IF NOT EXISTS (SELECT * FROM EmailsRecebidos 
                   WHERE De = @_DE
                   AND Assunto = @_ASSUNTO
                   AND Data = @_DATA)
   BEGIN
       INSERT INTO EmailsRecebidos (De, Assunto, Data)
       VALUES (@_DE, @_ASSUNTO, @_DATA)
   END
END

Thursday, April 21, 2016

list of stored pocs with specific table name







SELECT Name
FROM sys.procedures

WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%table name%'



------Example-------


SELECT Name
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%account_total%'

Thursday, April 7, 2016

SQL SERVER – Find Current Location of Data and Log File of All the Database



  • below query returns the current location of data and log file of all dbs in current server

 

                  SELECT name, physical_name AS current_file_locationFROM sys.master_files



  • Location for the  DB on local drive

              \Program Files\Microsoft SQL Server\MSSQL.90\MSSQL\Data\


                C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008\MSSQL