IF object_id ('dbo.spdeleterowdate_in_db') is not NULL DROP PROCEDURE dbo.spdeleterowdate_in_db gocreate proc spdeleterowdate_in_db (@compidint--Company ID) Asdeclare @tableName varchar ( -) DECLARE my_cursor Cursor--defines a cursor for (Selectobject_name (ID) fromsyscolumnswhereIdinch(SelectId fromsysobjectswhereType='U') and name='Compid') --isolate the desired set into the cursor open my_cursor;--Open cursor fetch NEXT from my_cursor to @tableName;--reads the first row of data (puts the table name into the @tablename variable) while @ @FETCH_STATUS=0BEGIN declare @sql nvarchar ( +) Set@sql ='Delete from'[Email protected]+'where compid='+convert (varchar ( -), @compid) print @sql exec (@sql) FETCH NEXT from My_cursor to @tableName; --read the next line of data endclose My_cursor;--close the cursor deallocate my_cursor;--release cursor Go--exec spdeleterowdate_in_db1
Traverse the database to delete the row data for the table that contains the specified columns-