Skip to main content

๐Ÿ‘ฉโ€๐Ÿ’ป ๆŸฅ่ฉขๆ‰€ๆœ‰ Table

ๆŸฅๅ‡บๆ‰€ๆœ‰ Tableโ€‹

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE';

ๅˆช้™คๆ‰€ๆœ‰ Tableโ€‹

DECLARE @table_schema varchar(100)
,@table_name varchar(100)
,@constraint_schema varchar(100)
,@constraint_name varchar(100)
,@cmd nvarchar(200)

DECLARE table_cursor CURSOR FOR
select TABLE_SCHEMA, TABLE_NAME
from INFORMATION_SCHEMA.TABLES
where TABLE_NAME != 'sysdiagrams'

OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @table_schema, @table_name

WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @cmd = 'DROP TABLE [' + @table_schema + '].[' + @table_name + ']'
--select @cmd
EXEC sp_executesql @cmd


FETCH NEXT FROM table_cursor INTO @table_schema, @table_name
END

CLOSE table_cursor
DEALLOCATE table_cursor
caution

ๅˆช้™คๅ‰ๅฟ…้ ˆๅ…ˆ ็งป้™คๆ‰€ๆœ‰ FK


REFโ€‹