Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DELETE TB1.*, TB2.*
- FROM TB1
- INNER JOIN TB2 ON TB1.PersonID = TB2.PersonID
- WHERE (TB1.PersonID)='2'
- DELETE FROM TB1 WHERE PersonID = '2';
- DELETE FROM TB2 WHERE PersonID = '2';
- DECLARE db_cursor CURSOR FOR
- SELECT name
- FROM master.dbo.sysdatabases
- WHERE name IN ("TB2","TB1") -- use these databases
- OPEN db_cursor
- FETCH NEXT FROM db_cursor INTO @name
- WHILE @@FETCH_STATUS = 0
- BEGIN
- DELETE FROM @name WHERE PersonID ='2'
- FETCH NEXT FROM db_cursor INTO @name
- END
- CREATE PROCEDURE sp_deleteUserDetails
- @Email varchar(255)
- AS
- declare @tempRegId as int
- Delete UserRegistration where Email=@Email
- set @tempRegId = (select Id from UserRegistration where Email = @Email)
- Delete UserProfile where RegID=@tempRegId
- RETURN 0
- DELETE t2
- FROM TB1 t1
- INNER JOIN TB2 t2 ON t1.PersonID = t2.PersonID
- WHERE t1.PersonID = '2'
- DECLARE @sqlCommand VARCHAR(3000);
- DECLARE @tableList TABLE(Value NVARCHAR(128));
- DECLARE @TableName VARCHAR(128);
- DECLARE @RecordCount INT;
- -- get a cursor with a list of table names and their record counts
- DECLARE MyCursor CURSOR FAST_FORWARD
- FOR SELECT t.name TableName,
- i.rows Records
- FROM sysobjects t,
- sysindexes i
- WHERE
- t.xtype = 'U' -- only User tables
- AND i.id = t.id
- AND i.indid IN(0, 1) -- 0=Heap, 1=Clustered Index
- AND i.rows < 10 -- Filter by number of records in the table
- AND t.name LIKE 'Test_%'; -- Filter tables by name. You could also provide a list:
- -- AND t.name IN ('MyTable1', 'MyTable2', 'MyTable3');
- -- or a list of tables to exclude:
- -- AND t.name NOT IN ('MySpecialTable', ... );
- OPEN MyCursor;
- FETCH NEXT FROM MyCursor INTO @TableName, @RecordCount;
- -- for each table name in the cursor, delete all records from that table:
- WHILE @@FETCH_STATUS = 0
- BEGIN
- SET @sqlCommand = 'DELETE FROM ' + @TableName;
- EXEC (@sqlCommand);
- FETCH NEXT FROM MyCursor INTO @TableName, @RecordCount;
- END;
- CLOSE MyCursor;
- DEALLOCATE MyCursor;
- DELETE TB1, TB2
- FROM customer_details
- LEFT JOIN customer_booking on TB1.cust_id = TB2.fk_cust_id
- WHERE TB1.cust_id = $id
- DELETE TB1, TB2 FROM TB1 INNER JOIN TB2
- WHERE TB1.PersonID = TB2.PersonID and TB1.PersonID = '2'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement