开发者

alert before deleting sql databases through a winform application [closed]

开发者 https://www.devze.com 2023-02-13 17:47 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot 开发者_StackOverflowbe reasonably answered in its current
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot 开发者_StackOverflowbe reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

so whats the way to do this?


You can run a SQL Statement similar to this

select 1 as DBExists from master.sys.databases where name = '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

select COUNT (*) as NumTables from YourDatabaseNameGoesHere.INFORMATION_SCHEMA.TABLES

If the dataset has rows, then display a messagebox with the appropriate message and then if the answer is "Yes" then drop the database.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号