Save (Not Permitted) Dialog Box. Tables will need to be dropped and re-created

 
SQL SSMS
Tools > Options > Designers > Tables and Database Designers
Check or Uncheck > Prevent saving changes that require table re-creation
 

SQL Server Profiler – “Not enough memory was available for trace”

 
Need to enable AWE on SQL Server which is an element of memory
Before doing this need to follow
"How to: Enable the Lock Pages in Memory Option (Windows)"
 
Then "Enabling AWE Memory for SQL Server"
 
The following is copied from there:
—————————————–
 
"Example

The following example shows how to activate AWE and configure a limit of 1 GB for min server memory and 6 GB for max server memory.
First, configure AWE:
Copy Code

sp_configure 'show advanced options', 1
RECONFIGURE
GO

sp_configure 'awe enabled', 1
RECONFIGURE
GO

After SQL Server restarts, the following message is written to the SQL Server error log: "Address Windowing Extensions enabled."
Next, configure memory:
Copy Code

sp_configure 'min server memory', 1024
RECONFIGURE
GO

sp_configure 'max server memory', 6144
RECONFIGURE
GO

 

Dataset loses default connection My.MySettings when moved between projects

 
When moving dataset from one project to another, for example to create N-Tier then it may well lose the default connection. It is almost right but loses the My.MySettings bit.
 
Open DS.xsd file in notepad
Locate PropertyReference=”ApplicationSettings.ProjectName.MySettings.GlobalReference.Default.conStr…”
Change to PropertyReference=”ApplicationSettings.ProjectName.My.MySettings.GlobalReference.Default.conStrOperaDataset”

SQL Database Mail – User security to allow facility

 
Security > Logins > Pick Login > Properties > User Mapping > msdb > tick on
Database role membership include DatabaseMailUserRole
 
msdb has more database role memberships. May be resolution to LinkedServer issue. 
 
PROBLEM
Procedure sp_send_dbmail, line 141 profile name is not valid
 
SOLVED
 
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @principal_name = 'ApplicationUser',
    @profile_name = 'AdventureWorks2008R2 Administrator Profile',
    @is_default = 1 ;
 
 

Padding Numbers Leading Zeros Using Transact-SQL

 
From
 
Use Str function which converts numeric data to a string.
 
SELECT replace(str(1,5),’ ‘,’0’)        — Outputs ‘00001’
SELECT replace(str(123,5),’ ‘,’0’) — Outputs ‘00123’
SELECT replace(str(12345,5),’ ‘,’0’)    — Outputs ‘12345’
SELECT replace(str(123456,5),’ ‘,’0’)   — Outputs ‘*****’
 
there is a third argument to str function which is no of decimals to keep
 
 
 

SQL Server Database Mail Stopped

 
 
 
USE msdb ;
GO
EXECUTE dbo.sysmail_start_sp ;
GO
 
To get it going again. Also possible to right-click on Management > Database Mail > View Database Mail Log
 
 

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)