sqlserver版:
查询当前数据库下所有表名:
select * from sys.tables;
查询当前库下,一张表的表名,字段名,字段类型,字段长度:
select a.name 表名,b.name 字段名,c.name 字段类型,c.length 字段长度 from sysobjects a,syscolumns b,systypes c where a.id=b.id
and a.name='DSE_SYS_DISTRICT' and a.xtype='U'
and b.xtype=c.xtype
删除所有表的外键约束*************************/
DECLARE c1 cursor forselect 'alter table ['+ object_name(parent_obj) + '] drop constraint ['+name+']; 'from sysobjectswhere xtype = 'F'open c1declare @c1 varchar(8000)fetch next from c1 into @c1while(@@fetch_status=0)beginexec(@c1)fetch next from c1 into @c1endclose c1deallocate c1清空某个数据库所有表
use 数据库名(是要删除表的所在的那个数据库的名称)
GOdeclare @sql varchar(8000)while (select count(*) from sysobjects where type='U')>0beginSELECT @sql='drop table ' + nameFROM sysobjectsWHERE (type = 'U')ORDER BY 'drop table ' + nameexec(@sql)end
https://blog.csdn.net/chushudu