Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. DELETE TB1.*, TB2.*
  2. FROM TB1
  3. INNER JOIN TB2 ON TB1.PersonID = TB2.PersonID
  4. WHERE (TB1.PersonID)='2'
  5.  
  6. DELETE FROM TB1 WHERE PersonID = '2';
  7. DELETE FROM TB2 WHERE PersonID = '2';
  8.  
  9. DECLARE db_cursor CURSOR FOR
  10. SELECT name
  11. FROM master.dbo.sysdatabases
  12. WHERE name IN ("TB2","TB1") -- use these databases
  13.  
  14. OPEN db_cursor
  15. FETCH NEXT FROM db_cursor INTO @name
  16.  
  17.  
  18. WHILE @@FETCH_STATUS = 0
  19. BEGIN
  20.  
  21. DELETE FROM @name WHERE PersonID ='2'
  22.  
  23. FETCH NEXT FROM db_cursor INTO @name
  24. END
  25.  
  26. CREATE PROCEDURE sp_deleteUserDetails
  27. @Email varchar(255)
  28. AS
  29. declare @tempRegId as int
  30. Delete UserRegistration where Email=@Email
  31. set @tempRegId = (select Id from UserRegistration where Email = @Email)
  32. Delete UserProfile where RegID=@tempRegId
  33.  
  34. RETURN 0
  35.  
  36. DELETE t2
  37. FROM TB1 t1
  38. INNER JOIN TB2 t2 ON t1.PersonID = t2.PersonID
  39. WHERE t1.PersonID = '2'
  40.  
  41. DECLARE @sqlCommand VARCHAR(3000);
  42. DECLARE @tableList TABLE(Value NVARCHAR(128));
  43. DECLARE @TableName VARCHAR(128);
  44. DECLARE @RecordCount INT;
  45.  
  46. -- get a cursor with a list of table names and their record counts
  47. DECLARE MyCursor CURSOR FAST_FORWARD
  48. FOR SELECT t.name TableName,
  49. i.rows Records
  50. FROM sysobjects t,
  51. sysindexes i
  52. WHERE
  53. t.xtype = 'U' -- only User tables
  54. AND i.id = t.id
  55. AND i.indid IN(0, 1) -- 0=Heap, 1=Clustered Index
  56. AND i.rows < 10 -- Filter by number of records in the table
  57. AND t.name LIKE 'Test_%'; -- Filter tables by name. You could also provide a list:
  58. -- AND t.name IN ('MyTable1', 'MyTable2', 'MyTable3');
  59. -- or a list of tables to exclude:
  60. -- AND t.name NOT IN ('MySpecialTable', ... );
  61.  
  62. OPEN MyCursor;
  63.  
  64. FETCH NEXT FROM MyCursor INTO @TableName, @RecordCount;
  65.  
  66. -- for each table name in the cursor, delete all records from that table:
  67. WHILE @@FETCH_STATUS = 0
  68. BEGIN
  69. SET @sqlCommand = 'DELETE FROM ' + @TableName;
  70. EXEC (@sqlCommand);
  71. FETCH NEXT FROM MyCursor INTO @TableName, @RecordCount;
  72. END;
  73.  
  74. CLOSE MyCursor;
  75. DEALLOCATE MyCursor;
  76.  
  77. DELETE TB1, TB2
  78. FROM customer_details
  79. LEFT JOIN customer_booking on TB1.cust_id = TB2.fk_cust_id
  80. WHERE TB1.cust_id = $id
  81.  
  82. DELETE TB1, TB2 FROM TB1 INNER JOIN TB2
  83. WHERE TB1.PersonID = TB2.PersonID and TB1.PersonID = '2'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement