zoukankan      html  css  js  c++  java
  • Oracle sql例子

     1 create database oracle1
     2 create table class(id int primary key,name varchar(255))
     3 select * from class
     4 insert into class values(1,'一班')
     5 insert into class values(2,'二班')
     6 insert into class values(3,'三班')
     7 --创建学生表
     8 create table student(id int primary key,name varchar(255),cid int ,constraint FK_student_class foreign key(cid) references class(id))
     9 insert into student values(1,'Tom',1)
    10 --联合查询
    11 select * from student student left join class class on student.cid=class.id
    12 select * from class class right join student student on class.id=student.cid
    13 --alter
    14 create table school(id int,name varchar(255))
    15 insert into school values(1,'耶鲁大学')
    16 
    17 
    18 alter table school add primary key(id)
    19 alter table class add sid int
    20 alter table class add constraint FK_class_school foreign key(sid) references school(id)
    21 
    22 
    23 update class set sid=1 where id=1
    24 
    25 
    26 ---联合查询  as后面的内容是作为别名存在的,是变量不是字符串
    27 select school.name as 大学,class.name as 班级 ,student.name as 姓名 from student student left join class class on student.cid=class.id left join school school on class.sid=school.id
    28 --union all
    29 select name from school
    30 union all
    31 select name from class
    32 union all
    33 select name from student
    34 
    35 
    36 /** 查询syscolumns**/
    37 select * from dba_tables
    38 select * from dba_tables where table_name=upper('class')
    39 select * from user_tables where table_name=upper('class')
    40 
    41 
    42 --数据库本身就是有多权限的系统,有dba的tables有user的tables 个人感觉Oracle的权限分配比sql Server2005要清晰明确的多
  • 相关阅读:
    eclipse 提交代码至自己的github上
    今天是国庆
    我要完蛋了!!!
    C/C++知识点
    [c++]const增强
    [c++]指针作为函数参数传递的问题
    day3_JavaScript
    day2_HTML&CSS
    2017年度总结
    小游戏
  • 原文地址:https://www.cnblogs.com/zhanghaiyublog/p/3583333.html
Copyright © 2011-2022 走看看