I want that on a new installation of my .net winforms application, which uses sql server 2005 express , it would drop old databases if exist but before deleting them , it alerts that the databases are empty or not by showing a message box i.e. they contain tables or not , & then creates new databases.
我希望在一个新的安装。net winforms应用程序,它使用sql server 2005 express,它将放弃旧的数据库,如果存在,但在删除之前,警报数据库是空的或不通过显示一个消息框即与否,它们包含表&然后创建新的数据库。
so whats the way to do this?
那么怎么做呢?
1 个解决方案
#1
1
You can run a SQL Statement similar to this
您可以运行类似于此的SQL语句。
select 1 as DBExists from master.sys.databases where name = 'YourDatabaseNameGoesHere'
从master.sys中选择1作为DBExists。数据库名称= 'YourDatabaseNameGoesHere'
If the dataset has rows, then the database exists!
如果数据集有行,那么数据库就存在!
You can find the number of tables in it (to see if it is empty or not) by running this SQL
你可以找到表的数量(是否为空或不)通过运行SQL
select COUNT (*) as NumTables from YourDatabaseNameGoesHere.INFORMATION_SCHEMA.TABLES
select COUNT(*)从YourDatabaseNameGoesHere.INFORMATION_SCHEMA.TABLES NumTables
If the dataset has rows, then display a messagebox with the appropriate message and then if the answer is "Yes" then drop the database.
如果数据集有行,那么显示带有适当消息的消息框,然后如果答案是“是”,则删除数据库。
#1
1
You can run a SQL Statement similar to this
您可以运行类似于此的SQL语句。
select 1 as DBExists from master.sys.databases where name = 'YourDatabaseNameGoesHere'
从master.sys中选择1作为DBExists。数据库名称= 'YourDatabaseNameGoesHere'
If the dataset has rows, then the database exists!
如果数据集有行,那么数据库就存在!
You can find the number of tables in it (to see if it is empty or not) by running this SQL
你可以找到表的数量(是否为空或不)通过运行SQL
select COUNT (*) as NumTables from YourDatabaseNameGoesHere.INFORMATION_SCHEMA.TABLES
select COUNT(*)从YourDatabaseNameGoesHere.INFORMATION_SCHEMA.TABLES NumTables
If the dataset has rows, then display a messagebox with the appropriate message and then if the answer is "Yes" then drop the database.
如果数据集有行,那么显示带有适当消息的消息框,然后如果答案是“是”,则删除数据库。