oracle和mysql数据库创建表之前判断表是否存在,如果存在则删除已有表,以及在这两个库中创建表

来源:互联网 发布:多线程编程java代码 编辑:程序博客网 时间:2024/05/01 05:56

在mysql中:

-- ----------------------------
-- Table structure for `article`
-- ----------------------------

--判断表是否存在,如果存在则删除
DROP TABLE IF EXISTS `article`;
CREATE TABLE `article` (
  `id` int(11) NOT NULL auto_increment,
  `userid` int(11) NOT NULL,
  `title` varchar(100) NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;


在oracle中:

/*
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)
);

0 0