• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 512
  • Last Modified:

SQL - Error in creating stored procedure

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
tommym121
Asked:
tommym121
2 Solutions
 
micropc1Commented:
See if granting permissions to your account helps...

GRANT CREATE PROCEDURE to [sa]

Open in new window

0
 
sachinpatil10dCommented:
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
 
tommym121Author Commented:
Thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now