c# sqlite判断某表是否存在的方法
方法1:
sqlCommand.CommandText = "select count(*) from sqlite_master where name='表名' and type='table';";
if (Convert.ToInt32(command.ExecuteScalar()) <= 0) //表不存在
sqlite_master是SQLite系统表,记录了数据库中所有表的信息。
方法2:
command.CommandText = "select name from sqlite_master where name='表名' and type='table';";
如果表不存在, command.ExecuteScalar()会返回空.
测试了一下,当表的数量很大时,判断表是否存在的速度会大幅降低.但如果此时判断的是一个已存在的表,方法2明显速度更快.其它情况则差别不明显.
where name='表名' and type='table'比where type='table' and name='表名'略快;
原文地址:https://blog.csdn.net/qq_21315789/article/details/142437493
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!