zoukankan      html  css  js  c++  java
  • 企业面试题库_数据库部分

    使用存储过程进行分页,页面使用javascript分页 JavaDotnet  
    如有城市表和蔬菜表,用SQL语句查询城市表,删除编号为2号的蔬菜, 为蔬菜表的蔬菜名称字段中添加土豆 题不全,无法做  
    sql查询:查询出一个表中四川省和湖南省所有姓李的人的姓名 select * from table where Province in('sichuan','hunan') and name like ('li%') 子查询
    左联接在什么时候应用 需要显示左表中所有数据,右表中对应数据. 查询语句
    sql查询:找出张三的同乡 select * from people where hometown=(select hometown from people where name='张三') 子查询
    查询学员表中英语一门成绩最高的人 select * from students where score in (
                           select max(score)  from students where object='英语' )  and  object='英语'
    子查询
    查询学员表中有两门以上不及格的人 select *  from students   where score in (
                           select max(score)  from students where object='英语')  and  object='英语'
    子查询
    查询出各年级中男女的人数 select  classid,sex,count(*) 人数 from  table  group by classid,sex  分组查询
    写一条SQL语句 筛选出不重复的数据? select * from table where id in(select id  from table group by id  having count(id)=1) 分组子查询
    oracle数据库TEST表(name,age(出生日期))中年龄大于10周岁的 姓名? select name from test where  months_between(sysdate,age)>10*12 数据库常用函数
    写一个得到查询orcle数据库里面的记录的方法? JavaDotnet  
    写一个存储过程或触发器? oracle存储过程
    CREATE OR REPLACE PROCEDURE query_employee
    (eno NUMBer,name OUT VARCHAR2,salary  OUT NUMBER)
    IS
    BEGIN
     select ename,sal into name,salary FROM emp WHERE empno=eno;
    EXCEPTION
     WHEN NO_DATA_FOUND THEN
      RAISE_APPLICATION_ERROR(-20000,'
    雇员不存在');
    END;
    oracle
    触发器:
    create or replace trigger tr_sec_emp
      after insert or update or delete on emp 
    declare
     v_count number;
    begin
     select count(*) into v_count from emp where sal=0;
     dbms_output.put_line(v_count);
    end tr_sec_emp;
    存储过程触发器
    什么是数据库的内连接,有几种形式 内连接:若连接的结果集中只保留了符合连接条件的元组,而排除了两个表中没有对应的或匹配的元组情况,这种连接称为内连接。
    两种形式
    :一个表做内连接;两个表做内连接.
    表连接查询
    编写SQL语句,删除一个表中的重复记录,假如表中有一个name字段,name重复即为重复记录 delete from table where name in(
                    select name  from table  group by name  having count(name)>1)
    分组子查询
    delete from tableA与truncate table tableA的区别 1.delete是数据操作语言,操作会写入日志,在未提交之前可以回滚;truncate是数据定义语言,不写入日志,不可回滚
    2.truncate执行效率比delete高
    3.delete可以根据条件删除数据;truncate会删除表中所有的记录
    数据库基础
    查询出Test表中重复三次以上的记录 1.创建表:create table test (id int,col1 varchar(3),col2 varchar(3))
    2.
    假设所有字段都重复,包括3次
    select * from test where id in (select id from test  group by id,col1,col2 having count(*)>=3)
    分组子查询
    查询出user表中用户名和密码相同的记录,并查询出重复出现的次数。User(UserName,password,description) select userName,password,count(*) from test group by userName,password having count(*)>1 分组查询
    索引列 product  SQL语句 select * from product where sal*12<5000; 优化此语句,简述原因 select * from product where sal<5000/12
    计算和函数会使索引列失效,因此改为不对索引列进行计算,就可以利用到索引列,提高查询效率
    SQL调优
    查询出表中salary最高的前三位。Test(user,salary) 1.不考虑并列情况
       select top 3 * from test order by salary desc
    2.
    考虑并列的情况
       SELECT * FROM  (SELECT user,salary,dense_rank() over(order by salary desc) as drank from test )
       where rank<4
    查询语句
    查询ID重复三条以上的记录 与17题雷同
    select * from test where id in (select id from test  group by id having count(*)>=3)
    分组子查询
    SQL查询语句中的关键字like对查询有影响吗?如果有,有什么影响? 有影响,会降低查询效率 SQL调优
    SQL中都有哪些类型?试写出至少3 字符型:char varchar 数字型:int numeric 日期型:datetime 数据库基础
    Oracle中是物理组件有哪些? 数据文件:用于存储数据库数据,如表、索引数据等
    控制文件:记录数据库物理结构的二进制文件
    日志文件:记录对数据库的所有修改信息,用于故障恢复
    Oracle基础知识
    重写日志文件对数据有什么用? 记录对数据库的所有修改信息,用于故障恢复 Oracle基础知识
    控制文件有什么用? 记录数据库物理结构,如数据库名,文件存放位置等等。启动数据库时需要读取该文件信息 Oracle基础知识
    ORACLE中的逻辑组件有那些 表空间、段、区、数据块 Oracle基础知识
    表空间与模式的关系 表空间不属于任何模式,可以为多个模式所共有 Oracle基础知识
    SQL语句创建用户,并赋权 1.创建用户,使用默认表空间
    CREATE USER user1 IDENTIFIED BY user1 DEFAULT TABLESPACE USERS
    TEMPORARY TABLESPACE TEMP;
    2.
    赋与dba的权限
    grant  dba to user1
    Oracle基础知识
    什么函数用于获取时间,怎么获取 日,月, 1.获取时间  select getdate() from tabName
    2.
    获取日月年
    SELECT DATEPART(day,GETDATE()) AS '',datepart(month,getdate()) as '',datepart(year,getdate()) as ''
    数据库常用函数
    怎样使用通配符%_ %是模糊查询,_匹配单个字符
    例如:
    select * from test where name like 'a%';
    SELECT *    FROM test  WHERE name LIKE 'j___s';
    数据库常用运算符
    怎么在数据库中插入单引号 1.利用数据库本身提供的转义字符,如oracle中''''则可插入'
    2.借助ASCII码转换函数插入
    数据库常用函数
    not in NOT exists的区别 1.not in 后面跟着结果集,not exists后返回的是true或者false
    2.not in一般需要进行全表扫描,大部分情况下效率比not exists要低
    3.形如select * from t1 where f1 not in (select f1 from t2 where t2.fx= 'x '),
    其中子查询的where里的条件不受外层查询的影响,这类查询一般情况下,自动优化会转成exist语句,
    也就是效率和not exist一样。 
    4.形如select * from t1 where f1 not in(select f1 from t2 where  t2.fx=t1.fx),
    其中子查询的where里的条件受外层查询的影响,这类查询的效率要看相关条件涉及的字段的索引情况
    和数据量多少,一般认为效率不如not exists。    
    SQL调优
    用一条语句将第一和第二张表连接成第三张表 select   *   from   A     union   all     select   *   from   B     ----2个表的全部记录(包括重复的,不排序)  
      or      
    select   *   from   A     union      select   *   from   B     -----
    排序并去掉重复的记录  
     
  • 相关阅读:
    winfrom 对话框
    容器控件
    简单记事本整理
    公共控件
    winfrom。布局
    ado 小测试
    ado.not--更改精简练习
    ado.not--数据库防字符串注入攻击学习及 练习
    ado.not--练习题
    ado.not--添加练习题
  • 原文地址:https://www.cnblogs.com/soundcode/p/1910663.html
Copyright © 2011-2022 走看看