1、打开plsql客户端,登录oracle数据库;
2、创建一个测试表,create table test_exists(id number, value varchar2(20))
3、编写sql,插入oracle系统视图,查询刚建的表是否存在,
select * from user_tables t where table_name= upper('test_exists');可以看到有查询结果,也就是说存在该表;
4、相反的,编写sql,查询test_exists2表是否存在,因没有返回结果,则说明该表并不存在;select * from user_tables t where table_name= upper('test_exists2');
#region 判断数据库表是否存在,通过指定专用的连接字符串,执行一个不需要返回值的SqlCommand命令。/// <summary>
/// 判断数据库表是否存在,返回页头,通过指定专用的连接字符串,执行一个不需要返回值的SqlCommand命令。
/// </summary>
/// <param name="tablename">bhtsoft表</param>
/// <returns></returns>
public static bool CheckExistsTable(string tablename)
{
String tableNameStr = "select count(1) from sysobjects where name = '" + tablename + "'"
using (SqlConnection con = new SqlConnection(ConnectionString))
{
con.Open()
SqlCommand cmd = new SqlCommand(tableNameStr, con)
int result = Convert.ToInt32(cmd.ExecuteScalar())
if (result == 0)
{
return false
}
else
{
return true
}
}
}
#endregion
select * from tabs where table_name ='AAA'如果查询结果不是空的,就说明存在这个表
然后AAA处是表名,必须要大写
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)