2010-09-18 20 views

cevap

7

deneyin böyle bir şey:

mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP | mysql -u[USERNAME] -p[PASSWORD] [DATABASE] 

Temiz küçük bir hile ve benim için çalışıyor.

Öncelikle önerilen here.

+0

Not. – Mchl

+0

Sadece mysql deyimlerini çalıştırabilirim, bu yüzden bu işe yaramaz sanırım – aneuryzm

0

bu deneyin:

SELECT name INTO #tables from sys.objects where type = 'U' 
while (SELECT count(1) FROM #tables) > 0 
begin 
declare @sql varchar(max) 
declare @tbl varchar(255) 
SELECT top 1 @tbl = name FROM #tables 
SET @sql = 'drop table ' + @tbl 
exec(@sql) 
DELETE FROM #tables where name = @tbl 
end 
DROP TABLE #tables; 

here bu var. Çabuk ve kirli, diyor. Kesinlikle kirli. ;-)

+0

işe yaramıyor .. Synatax hatası diyor. Tahminimce: & gt; 0 MySQL olmadığı için büyük olasılıkla daha büyük olasılıkla – aneuryzm

+0

. Bu gibi bir prosedür, sys.objects (ve değişkenler için MySQL uyumlu sözdizimi) yerine information.schema kullanılarak MySQL'de oluşturulabilir. – Mchl

0
İşte

bir örnek, ama MS SQL Server içindir: Bu değil MySQL ifadesi olarak, sistem komut satırından çalıştırılacak olduğunu

USE myBD -- user DB 

DECLARE tables_cursor CURSOR 
FOR SELECT name FROM sys.objects WHERE type = 'U' --carefull here 

OPEN tables_cursor 
DECLARE @tablename sysname 

FETCH NEXT FROM tables_cursor INTO @tablename 
WHILE (@@FETCH_STATUS != -1) 
BEGIN 
EXEC ('DROP TABLE ' + @tablename) 
FETCH NEXT FROM tables_cursor INTO @tablename 
END 

DEALLOCATE tables_cursor 
İlgili konular