由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 如何用SQL语句判断一个TABLE是否存在?
相关主题
the most stupid questionIn MySQL, 如何在procedure里create trigger?谢谢了?
初级问题SQL求助
SQL help.讨论:在SELECT中限制TOP N条纪录
SQL问题请教: add one more column这几天Oracle 92I经常出现ORA-00600的错误
如何把Access Table输出为SQL语句?请教请教:trigger 里得不到blob值是怎么回事儿?
请问一个SQL语句的优化问题请教: SQL SUM
Do replicated tables need identical?请教:PL/SQL
一个oracle query, 求问oracle pl sql recursive function
相关话题的讨论汇总
话题: table话题: isthere话题: sql话题: mytable话题: name
进入Database版参与讨论
1 (共1页)
o**s
发帖数: 1
1
各位高手:
我想实现下面的SQL块语句
begin
if TABLE是否存在
delete from TABLE;
else
create TABLE;
...
end
谢了
g*s
发帖数: 2277
2
sql server is
exists(select * from sysobjects where name='table_name' and type='U')

【在 o**s 的大作中提到】
: 各位高手:
: 我想实现下面的SQL块语句
: begin
: if TABLE是否存在
: delete from TABLE;
: else
: create TABLE;
: ...
: end
: 谢了

w****g
发帖数: 1
3
in Oracle, try this one.
declare
isThere varchar2(1);
begin
select 'Y' into isThere
from user_tables
where table_name = 'MYTABLE';
if isThere = 'Y' then
truncate table MYTABLE;
else
create table MYTABLE (....);
end if;
end;

【在 o**s 的大作中提到】
: 各位高手:
: 我想实现下面的SQL块语句
: begin
: if TABLE是否存在
: delete from TABLE;
: else
: create TABLE;
: ...
: end
: 谢了

s***t
发帖数: 7
4
it won't work. An error will be generated if more than
one table have the same name under different schemas.
declare
isThere varchar2(1) := 'N';
begin
select 'Y' into isThere
from dual
where exists
(select null from all_tables
where table_name = 'ABC');
if isThere = 'Y' then
dbms_output.put_line('exists');
end if;
exception
when no_data_found then
dbms_output.put_line('not exists');
end;

【在 w****g 的大作中提到】
: in Oracle, try this one.
: declare
: isThere varchar2(1);
: begin
: select 'Y' into isThere
: from user_tables
: where table_name = 'MYTABLE';
: if isThere = 'Y' then
: truncate table MYTABLE;
: else

m******t
发帖数: 2416
5
In SQL Server, this will do it:
if exists (select * from sysobjects where id = object_id(N'tableName')
and OBJECTPROPERTY(id, N'Table') = 1)
s****j
发帖数: 14
6
In Oracle
select * from dba_tables where table_name = 'TABLE_NAME'

【在 m******t 的大作中提到】
: In SQL Server, this will do it:
: if exists (select * from sysobjects where id = object_id(N'tableName')
: and OBJECTPROPERTY(id, N'Table') = 1)

1 (共1页)
进入Database版参与讨论
相关主题
oracle pl sql recursive function如何把Access Table输出为SQL语句?请教
another question--怎么delete a row from a table请问一个SQL语句的优化问题
Help!!!! How to synchronized the data in SQL serverDo replicated tables need identical?
如何only update the first occurrence in a table一个oracle query, 求问
the most stupid questionIn MySQL, 如何在procedure里create trigger?谢谢了?
初级问题SQL求助
SQL help.讨论:在SELECT中限制TOP N条纪录
SQL问题请教: add one more column这几天Oracle 92I经常出现ORA-00600的错误
相关话题的讨论汇总
话题: table话题: isthere话题: sql话题: mytable话题: name