Solved

SQL - Error in creating stored procedure

Posted on 2012-03-18
3
495 Views
Last Modified: 2012-03-19
I have an error of
Msg 262, Level 14, State 1, Procedure SearchAllTablesForSimilarValue, Line 65
CREATE PROCEDURE permission denied in database 'Database1'.

I sign on as 'sa'.  Not sure why the error occur. How do I find out why?  

USE [Database1]
GO
/****** Object:  StoredProcedure [dbo].[SearchAllTablesForSimilarValue]    
Script Date: 01/03/2012 22:27:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[SearchAllTablesForSimilarValue]
(
      @SearchStr nvarchar(100)
)
AS
BEGIN

      -- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
      -- Purpose: To search all columns of all tables for a given search string
      -- Written by: Narayana Vyas Kondreddi
      -- Site: http://vyaskn.tripod.com
      -- Tested on: SQL Server 7.0 and SQL Server 2000
      -- Date modified: 28th July 2002 22:50 GMT


      CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

      SET NOCOUNT ON

      DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
      SET  @TableName = ''
      SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

      WHILE @TableName IS NOT NULL
      BEGIN
            SET @ColumnName = ''
            SET @TableName =
            (
                  SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
                  FROM       INFORMATION_SCHEMA.TABLES
                  WHERE             TABLE_TYPE = 'BASE TABLE'
                        AND      QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
                        AND      OBJECTPROPERTY(
                                    OBJECT_ID(
                                          QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
                                           ), 'IsMSShipped'
                                           ) = 0
            )

            WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
            BEGIN
                  SET @ColumnName =
                  (
                        SELECT MIN(QUOTENAME(COLUMN_NAME))
                        FROM       INFORMATION_SCHEMA.COLUMNS
                        WHERE             TABLE_SCHEMA      = PARSENAME(@TableName, 2)
                              AND      TABLE_NAME      = PARSENAME(@TableName, 1)
                              AND      DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
                              AND      QUOTENAME(COLUMN_NAME) > @ColumnName
                  )
      
                  IF @ColumnName IS NOT NULL
                  BEGIN
                        INSERT INTO #Results
                        EXEC
                        (
                              'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
                              FROM ' + @TableName + ' (NOLOCK) ' +
                              ' WHERE ' + @ColumnName + ' Like ' + @SearchStr2
                        )
                  END
            END      
      END

      SELECT DISTINCT ColumnName, ColumnValue FROM #Results  -- <== Error point to this line
      ORDER BY ColumnName ASC
END
0
Comment
Question by:tommym121
3 Comments
 
LVL 7

Accepted Solution

by:
micropc1 earned 400 total points
ID: 37736233
See if granting permissions to your account helps...

GRANT CREATE PROCEDURE to [sa]

Open in new window

0
 
LVL 9

Assisted Solution

by:sachinpatil10d
sachinpatil10d earned 100 total points
ID: 37736315
what micropc1 says is right

Msg 262, Level 14, State 1, Procedure SearchAllTablesForSimilarValue, Line 65
CREATE PROCEDURE permission denied in database 'Database1'.

error occurs generally when sa user does not have the permission to create procedure, function etc.

you will have to assign the create permission to user sa.

for Grant command check out the following link

http://msdn.microsoft.com/en-us/library/ms187965.aspx
0
 

Author Closing Comment

by:tommym121
ID: 37737128
Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
T-SQL: Do I need CLUSTERED here? 13 45
convert null in sql server 12 34
Create snapshot on MSSQL 2012 3 20
access query to sql server 3 22
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question