/******************************************************************************/
/*
主流数据库MYSQL/MSSQL/ORACLE测试数据库脚本代码
脚本任务:建立4个表,添加主键,外键,插入数据,建立视图
运行环境1:microsoft sqlserver 2000 查询分析器
运行环境2:mysql5.0 phpMyAdmin网页界面
运行环境3:oracle 9i SQL*PLUS命令行界面
author:chinayaosir
blog:   http://blog.csdn.net/chinayaosir/
QQ:    44633197

声明:严禁其它网站不经过作者chinayaosir同意任意转载

*/
/******************************************************************************/
/*script test ok with microsoft sqlserver 2000 查询分析器 */
/******************************************************************************/
/*DB:MSSQL2000 SCRIPT*/
/*0.drop table list*/
    drop  table Employee;
    drop  table Department;
    drop  table Post;
    drop  table Account;
/*********************************************************/
/*DB:MSSQL2000 SCRIPT*/
/*1.create all table*/
create table Account(
    oid     int  not null,
    username varchar(30) not null,
    password varchar(10)  null,
    invalid    varchar(1)  null          
);
create table bab.Post(
    /*oid     int identity(1,1) not null primary key,*/
    oid     int  not null,
    postName varchar(30) not null
);

create table Department(
    oid     int  not null,
    deptName varchar(30) not null,
    parentid  int  null,
    manager   varchar(30)  null,
    email     varchar(30)  null
);

create table Employee(
    oid     int  not null,
    empName varchar(30) not null,
    postid  int  null,
    deptid    int  null,
    phone   varchar(20)  null,
    birthday varchar(10)  null
);
/*********************************************************/
/*DB:MSSQL2000 SCRIPT*/
/*2.add constraint with primary key */
alter table Account    add constraint Account_pk primary key(oid);
alter table Post    add constraint Post_pk primary key(oid);
alter table Department    add constraint Department_pk primary key(oid);
alter table Employee    add constraint Employee_pk primary key(oid);

/*********************************************************/
/*DB:MSSQL2000 SCRIPT*/
/*3.add constraint with foreign key */
alter table Department    add constraint Department_fk
foreign key(parentid) references Post(oid)
on update cascade on delete cascade;

alter table Employee add constraint Employee_fk1
foreign key(oid) references Account(oid)
on update cascade on delete cascade;

alter table Employee add constraint Employee_fk2
foreign key(postid) references Post(oid);

alter table Employee add constraint Employee_fk3
foreign key(deptid) references Department(oid);
/*********************************************************/
/*DB:MSSQL2000 SCRIPT*/
/*4. inert sample data into tables*/
insert into post(oid,postname) values(1,'office');
insert into post(oid,postname) values(2,'workshop');

insert into Department values(1,'R+D DEPT',1,'zhangshan','zhangshan@126.com');
insert into Department values(2,'SALE DEPT',1,'lishi','lishi@126.com');
insert into Department values(3,'MADE DEPT',2,'wanger','wanger@126.com');

insert into Account values(111,'user01','654123','1');
insert into Account values(112,'user02','963147','1');
insert into Account values(113,'user03','4456','1');

insert into Employee values(111,'smith lee',1,1,'13612345678','1970');
insert into Employee values(112,'ming yang',1,2,'13712345678','1980');
insert into Employee values(113,'san zhang',2,3,'13812345678','1990');
/*********************************************************/
/*DB:MSSQL2000 SCRIPT*/
/*5. create view*/
create view v_alltables
as
select  Employee.oid,
    Employee.empname,
    Account.username,
    Account.password,
    Account.invalid,
    post.postname,
    department.deptname,
    department.manager,
    department.email,
    Employee.phone,
    Employee.birthday
from      Employee,
          Account,
    post,
    department
where    Employee.oid=Account.oid and  
    Employee.postid=post.oid and  
    Employee.deptid=department.oid

/******************************************************************************/
/*script test ok with mysql5.0 phpMyAdmin */
/******************************************************************************/
/*DB:MYSQL SCRIPT*/
/*0.drop table list*/
    drop  table Employee;
    drop  table Department;
    drop  table Post;
    drop  table Account;
/*********************************************************/
/*DB:MYSQL SCRIPT*/
/*1.create all table*/
create table Account(
    oid     int  not null,
    username varchar(30) not null,
    password varchar(10)  null,
    invalid    varchar(1)  null          
);
create table Post(
    /*oid     int identity(1,1) not null primary key,*/
    oid     int  not null,
    postName varchar(30) not null
);

create table Department(
    oid     int  not null,
    deptName varchar(30) not null,
    parentid  int  null,
    manager   varchar(30)  null,
    email     varchar(30)  null
);

create table Employee(
    oid     int  not null,
    empName varchar(30) not null,
    postid  int  null,
    deptid    int  null,
    phone   varchar(20)  null,
    birthday varchar(10)  null
);
/*********************************************************/
/*DB:MYSQL SCRIPT*/
/*2.add constraint with primary key */
alter table Account    add constraint Account_pk primary key(oid);
alter table Post    add constraint Post_pk primary key(oid);
alter table Department    add constraint Department_pk primary key(oid);
alter table Employee    add constraint Employee_pk primary key(oid);

/*********************************************************/
/*DB:MYSQL SCRIPT*/
/*3.add constraint with foreign key */
alter table Department    add constraint Department_fk
foreign key(parentid) references Post(oid)
on update cascade on delete cascade;

alter table Employee add constraint Employee_fk1
foreign key(oid) references Account(oid)
on update cascade on delete cascade;

alter table Employee add constraint Employee_fk2
foreign key(postid) references Post(oid);

alter table Employee add constraint Employee_fk3
foreign key(deptid) references Department(oid);
/*********************************************************/
/*DB:MYSQL SCRIPT*/
/*4. inert sample data into tables*/
insert into post(oid,postname) values(1,'office');
insert into post(oid,postname) values(2,'workshop');

insert into Department values(1,'R+D DEPT',1,'zhangshan','zhangshan@126.com');
insert into Department values(2,'SALE DEPT',1,'lishi','lishi@126.com');
insert into Department values(3,'MADE DEPT',2,'wanger','wanger@126.com');

insert into Account values(111,'user01','654123','1');
insert into Account values(112,'user02','963147','1');
insert into Account values(113,'user03','4456','1');

insert into Employee values(111,'smith lee',1,1,'13612345678','1970');
insert into Employee values(112,'ming yang',1,2,'13712345678','1980');
insert into Employee values(113,'san zhang',2,3,'13812345678','1990');
/*********************************************************/
/*DB:MYSQL SCRIPT*/
/*5. create view*/
drop view v_alltables;

create view v_alltables
as
select  Employee.oid,
    Employee.empname,
    Account.username,
    Account.password,
    Account.invalid,
    post.postname,
    department.deptname,
    department.manager,
    department.email,
    Employee.phone,
    Employee.birthday
from      Employee,
          Account,
    post,
    department
where    Employee.oid=Account.oid and  
    Employee.postid=post.oid and  
    Employee.deptid=department.oid;

/******************************************************************************/
/*script test ok with Oracle 9i sql*plus */
/******************************************************************************/
/*DB:Oracle 9i sql*plus script*/
/*0.drop table list*/
    drop  table bab.Employee;
    drop  table bab.Department;
    drop  table bab.Post;
    drop  table bab.Account;
/
/*********************************************************/
/*DB:Oracle SCRIPT*/
/*1.create all table*/
create table bab.Account(
    oid     int  not null,
    username varchar(30) not null,
    password varchar(10)  null,
    invalid    varchar(1)  null          
);
/
create table bab.Post(
    /*oid     int identity(1,1) not null primary key,*/
    oid     int  not null,
    postName varchar(30) not null
);
/
create table bab.Department(
    oid     int  not null,
    deptName varchar(30) not null,
    parentid  int  null,
    manager   varchar(30)  null,
    email     varchar(30)  null
);
/
create table bab.Employee(
    oid     int  not null,
    empName varchar(30) not null,
    postid  int  null,
    deptid    int  null,
    phone   varchar(20)  null,
    birthday varchar(10)  null
);
/
/*********************************************************/
/*DB:Oracle SCRIPT*/
/*2.add constraint with primary key */
alter table bab.Account    add constraint Account_pk primary key(oid);
alter table bab.Post    add constraint Post_pk primary key(oid);
alter table bab.Department    add constraint Department_pk primary key(oid);
alter table bab.Employee    add constraint Employee_pk primary key(oid);
/
/*********************************************************/
/*DB:Oracle SCRIPT*/
/*3.add constraint with foreign key */
alter table bab.Department    add constraint Department_fk
foreign key(parentid) references bab.Post(oid);

alter table bab.Employee add constraint Employee_fk1
foreign key(oid) references bab.Account(oid);

alter table bab.Employee add constraint Employee_fk2
foreign key(postid) references bab.Post(oid);

alter table bab.Employee add constraint Employee_fk3
foreign key(deptid) references bab.Department(oid);
/
/*********************************************************/
/*DB:Oracle SCRIPT*/
/*4. inert sample data into tables*/
insert into post(oid,postname) values(1,'office');
insert into post(oid,postname) values(2,'workshop');

insert into Department values(1,'R+D DEPT',1,'zhangshan','zhangshan@126.com');
insert into Department values(2,'SALE DEPT',1,'lishi','lishi@126.com');
insert into Department values(3,'MADE DEPT',2,'wanger','wanger@126.com');

insert into Account values(111,'user01','654123','1');
insert into Account values(112,'user02','963147','1');
insert into Account values(113,'user03','4456','1');

insert into Employee values(111,'smith lee',1,1,'13612345678','1970');
insert into Employee values(112,'ming yang',1,2,'13712345678','1980');
insert into Employee values(113,'san zhang',2,3,'13812345678','1990');
/
/*********************************************************/
/*DB:Oracle SCRIPT*/
/*5. create view*/
drop view bab.v_alltables;
/
create view bab.v_alltables
as
select  Employee.oid,
    Employee.empname,
    Account.username,
    Account.password,
    Account.invalid,
    post.postname,
    department.deptname,
    department.manager,
    department.email,
    Employee.phone,
    Employee.birthday
from      Employee,
          Account,
    post,
    department
where    Employee.oid=Account.oid and  
    Employee.postid=post.oid and  
    Employee.deptid=department.oid;
/
/******************************************************************************/

MYSQL/MSSQL/ORACLE数据库脚本代码相关推荐

  1. Linux自动备份MySQL数据库脚本代码

    Linux自动备份MySQL数据库脚本代码 下面这段Linux的Shell脚本用于每日自动备份MySQL数据库,可通过Linux的crontab每天定时执行 在脚本中可设置需要备份的数据库表清单,并且 ...

  2. mysql 读取oracle_RobotFramework读取mysql和oracle数据库

    一.robotframework连接mysql数据库 1.安装databaselibrary.pymysql 通过cmd命令执行:pip install robotframework-database ...

  3. springcloud适配mysql和oracle数据库

    mysql和oracle数据库部分语法不相同,为了适配两种数据库(修改配置文件方式),可以先操作sql,然后通过代码级别再实现.比如oracle限制返回的条数:rownum<=1 但是mysql ...

  4. mysql,oracle数据库优化之索引

    mysql,oracle数据库优化之索引,分库分表,表分区,本地索引,全局索引 数据库引擎 数据库索引 索引类型 主键索引 唯一索引 普通索引 全文索引 位图索引(oracle数据库才有) 在哪些列上 ...

  5. mysql begin end 用法_超实用的Mysql动态更新数据库脚本的示例讲解(推荐)

    今天小编为大家分享一篇关于Mysql动态更新数据库脚本的示例讲解,具体的upgrade脚本如下: 动态删除索引 DROP PROCEDURE IF EXISTS UPGRADE;DELIMITER $ ...

  6. 使用MySQL Workbench导出数据库脚本以及出错时的解决办法

    使用MySQL Workbench导出数据库脚本以及出错时的解决办法 正常做法 打开workbench,选择左上角的菜单栏,选择Server->Data 之后出现如下界面 一般情况下,这样就导出 ...

  7. jsp mysql oracle_Jsp 连接 mySQL、Oracle 数据库备忘

    Jsp 连接 mySQL.Oracle 数据库备忘 2009-12-15 16:47 Jsp 环境目前最流行的是 Tomcat5.0.Tomcat5.0 自己包含一个 Web 服务器,如果是测试,就没 ...

  8. oracle数据库需要的端口号,SQL Server数据库、MySQL、Oracle数据库各自的默认端口号...

    我们今天主要向大家讲述的是SQL Server数据库.MySQL.Oracle数据库各自的默认端口号,以下就是对SQL Server数据库.MySQL.Oracle数据库各自的默认端口号的描述,望在你 ...

  9. RobotFramework读取mysql和oracle数据库

    一.robotframework连接mysql数据库 1.安装databaselibrary.pymysql 通过cmd命令执行:pip install robotframework-database ...

最新文章

  1. 《3ds Max疯狂设计学院》——1.5节怎样才能学好3ds Max,你要听好
  2. crysis3 android,Crytek谈安卓版《Crysis 3》:Tegra X1图形性能OK,瓶颈是CPU
  3. 删除web文本框中的内容需要或者文本框失去焦点,点击“Backspace”键时页面回退,屏蔽页面回退键的方法
  4. leetcode(2)---两数相加
  5. 8、mybatis中的sql映射文件详解(3)
  6. linux系统起来时间,linux 系统时间调整
  7. MD5 与 Base64一起使用 加密,计算原理
  8. 1到100的偶数之和是多少_什么白酒适合收藏,收藏多久出手,茅台五粮液老酒价格是多少?...
  9. 为vs2008添加Mobile Web Forms模板
  10. imp 数据导入_墨天轮数据库周刊—第7期
  11. 帆软日期格式转换_日期和时间函数- FineReport帮助文档 - 全面的报表使用教程和学习资料...
  12. 嵌入式设备移植触摸屏驱动
  13. linux scp传输文件权限被拒绝,Linux的远程传输文件scp及出现Permission denied (publickey).lost connection问题解决方法-Go语言中文社区...
  14. TLQ的安装路径不存在或不正确
  15. 关于开会了一点点想法
  16. Layui表单的验证
  17. mysql-repeatable read可以避免幻读
  18. CF1463F Max Correct Set(取小样法+状压 DP)
  19. 老师的经典口头禅,这一句最扎心
  20. JavaScript 数组array 插入[ push() ] 与 删除[ splice() ]

热门文章

  1. Cannot connect to license server system. (-15,570:150 - Operation now in progress)
  2. redis缓存序列化的泥坑
  3. VBA调整Excel格式~微软雅黑,左右居中对齐,上下居中对齐,10号字体,全部加边框,冻结首行~(公司固定格式)
  4. MAVEN 淘宝中央仓库
  5. 【Windows电脑快捷键-实用篇】
  6. 留学生学位学历认证流程
  7. 用zabbix监控交换机bfd协议
  8. Android原生的简单确定取消对话框用法
  9. 2023 新版WIFI大师分销微信源码小程序分销系统独立源码v4.47 带流量主
  10. 24岁零基础自学编程,先学哪种语言最好?