How do I find a text in SQL Object ?

 
Started with:
 
 
Adapted to:

ALTER PROCEDURE [Testing].[uspFindText]

@DatabaseName

nvarchar(50) = ‘EFI’
, @TextToFind nvarchar(100)
–, @Type int = 0 –0 = ALL, 1 = PROCEDURE

AS

DECLARE

@SQL nvarchar(500)
SELECT @SQL = ‘SELECT ROUTINE_TYPE, SPECIFIC_SCHEMA, ROUTINE_NAME, ROUTINE_DEFINITION
FROM [‘
+ @DatabaseName + ‘].INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE ”%’
+ @TextToFind + ‘%”’

–SELECT @SQL = @SQL + ‘ AND ROUTINE_TYPE=”PROCEDURE”’

PRINT

@SQL
EXECUTE(@SQL)

 

Check Validity of SQL Server Stored Procedures, Views and Functions

 
 
 

"When I set out to do this, someone reminded me of the "check syntax" feature in SQL Enterprise manager. If I could replicate this functionality, this would be ideal, as I didn’t want to actually compile the database objects – just simulate compilation. So I pulled out SQL profiler and recorded the statements that are executed when you press the "Check Syntax" button. Interestingly what happens when you press this button is the following:

Collapse Copy Code
SET NOEXEC ON
GO
CREATE PROC....etc
GO
SET NOEXEC OFF
GO
SET PARSEONLY OFF
GO

I had not come across these SET commands before. Looking them up in BOL tells me what you have already guessed:

  • SET NOEXEC "compiles each batch of Transact-SQL statements but does not execute them"
  • SET PARSEONLY "Checks the syntax of each Transact-SQL statement and returns any error messages without compiling or executing the statement"

SQL Server Intellisense Refresh

 

Actually this is because Objects are cached. You can refresh cache using

Edit -> Intellisense -> Refresh Local Cache (CTRL+Shift+R)

 

Find Views SchemaBinding

 

Other ways exist. For instance in code.

CREATE PROCEDURE [dbo].[uspViewsSchemaBound]
(@DatabaseName nvarchar(50))
AS

DECLARE

@SQL nvarchar(200)
SET @SQL = ‘SELECT * FROM ‘ + @DatabaseName + ‘.INFORMATION_SCHEMA.VIEWS WHERE VIEW_DEFINITION LIKE ”%WITH SCHEMABINDING%”’
EXECUTE (@SQL)

 

 

How to Count No. of Occurences of a Character in a String

 
 
LEN(ColumnToCheck) – LEN(REPLACE(ColumnToCheck,"N",""))
 
If it is more complex then see
 
 

sp_rename

 
 

B. Renaming a column

The following example renames the TerritoryID column in the SalesTerritory table to TerrID.

USE AdventureWorks;
GO
EXEC sp_rename 'Sales.SalesTerritory.TerritoryID', 'TerrID', 'COLUMN';
GO

 

Cannot create an instance of OLE DB provider “VFPOLEDB” for linked server “Opera”.

Unsolved

Msg 7302, Level 16, State 1, Line 1
Cannot create an instance of OLE DB provider “VFPOLEDB” for linked server “”.

Click here for one part of solution Social.msdn

in Server Objects > Linked Servers > Providers > VFPOLEDB > General tab > Provider options > Allow inprocess. Also, you can
change the InProcess setting with the following code:

USE [master]
GO
EXEC master.dbo.sp_MSset_oledb_prop N’VFPOLEDB’, N’AllowInProcess’, 1
GO

Then get a new message
OLE DB provider “VFPOLEDB” for linked server “Opera” returned message “Invalid path or file name.”.

Cannot initialize the data source object of OLE DB provider “VFPOLEDB” for linked server

 

TRUNCATE TABLE – Generates error “Cannot find object * because it does not exist or you do not have permission”

 
Generates error
cannot find the object "%.*ls" because it does not exist or you do not have permissions.
 
TRUNCATE needs higher permission than DELETE FROM
Needs Alter control on table. This may be too high for entire schema and may really be too high for object.
So workarounds are:-
 
Use WITH EXECUTE AS SELF
AS SELF means execute as the person who created the s.p
 
 
http://msdn.microsoft.com/en-us/library/ms177570.aspx   – See permissions in this article
 
 
ALSO as a secondary note on TRUNCATE TABLE.
Truncate is not allowed if there are any Foreign Keys on the table
 
Steve
 
 
 

Transfer SQL Server 2008 Database and Data to SQL Server 2005

 
11/08/2009 This works !! 
 
 
Also
 
 
SSMS > Select database > Right Click > Tasks > Generate Scripts > Proceed to "Choose Script Options" 
> Under "General" change option for Script for Server Version to SQL Server 2005 or 2000
> Can not see this but "If you are putting the database on a new instance for the first time, make sure the "Script Database Create" option is set to "True.""
> under "Table/View Options" select Script Data to True
> Proceed through rest of options choosing your preferences.
 
 
 
 
 
 

SQL Server Timeout Expired on Redesign of Table with many rows

 
 
Go to SSMS > Tools > Options > Designers > Table and Database Designers >
and change Transaction Timout After from default of 30 seconds to something larger.
 
May well also be necessary to temporarily increase the log file size. Then return it back to it’s previous size