1. 程式人生 > >oracle和mysql資料庫建立表之前判斷表是否存在,如果存在則刪除已有表,以及在這兩個庫中建立表

oracle和mysql資料庫建立表之前判斷表是否存在,如果存在則刪除已有表,以及在這兩個庫中建立表

/*
Navicat Oracle Data Transfer
*/
------------------------------
-- Table structure for `article`
-- ----------------------------
--判斷表是否存在,如果存在則刪除


declare 
      v_exists   number;
begin
select count (*) into v_exists from user_tables where table_name = 'ARTICLE'; 
    if v_exists > 0 then
    execute immediate 'drop table article';  
    end if;
end;


CREATE TABLE article (
  id integer NOT NULL,
  userid integer NOT NULL,
  title varchar(100) NOT NULL,
  content varchar2(100) NOT NULL,
  PRIMARY KEY  (id)
);