zoukankan      html  css  js  c++  java
  • 数据库基础

    数据库:
    三个层次:文件--服务--界面  (DBMS)
    两种登录方式的设置:Windows身份登录;SqlServer身份登录。
    如何设置SQLServer身份验证?
    1.对象资源管理器右击--属性--安全性--SqlServer和Windows身份登录。
    2.对象资源管理器--安全性--登录--sa--右击--属性--常规--设置密码
    3.对象资源管理器--安全性--登录--sa--右击--属性--状态--授予,启用
    重启数据库服务。

    .ldf——日志文件
    .mdf——主数据文件
    .ndf——次数据文件
    一个数据库中,可以有多个日志文件,多个次数据文件,但只能有一个主数据文件。

    行次序无关,列次序无关。

    SQL语句  DDL DML(增、删、改、查) DCL


    insert into 表名(列名,列名,列名,...) values(值,值,值,....)
    insert into 表名 values(值,值,值,值。。)


    一、简单查询
    select * from 表名
    select 列名,列名,...from 表名 ——投影
    等值与不等值查询
    select * from 表名 where 列名=值 --等值查询
    不等值查询
    select * from 表名 where 列名 <> 值
    select * from 表名 where 列名 > 值 >=
    select * from 表名 where 列名 < 值 <=

    多条件查询  逻辑与(and),逻辑或(or)
    select * from 表名 where 条件1 and 条件2 ...
    select * from 表名 where 条件1 or 条件2 ...
    如果在where筛选条件中,既出现and又出现or,则先运算and。除非使用小括号改变优
    先级。

    范围查询。
    select * from Car where Price >=30 and Price<=50
    select * from Car where Price between 30 and 50


    select * from Car where Oil=7.4 or Oil=8.5 or Oil=9.4
    select * from Car where Oil in(7.4,8.5,9.4)

    模糊查询。 一般不用=,而是用like
    %——任意多个任意字符
    _——一个任意字符
    select * from Car where Name like '宝马%'
    宝马%——以宝马开头的
    %宝马——以宝马结尾的
    %宝马%——只要含有宝马这两个字就可以。

    __宝马%——代表第三个字符以宝马开头的。

    去重查询:
    select distinct 列名 from car ——如果列中有重复值,则只查1个出来。

    取前几条数据
    select top 数量 [列名|*] from 表名

    排序
    select * from car order by price asc  ——默认是升序 ascending descending
    select * from car order by price desc
    select * from Car order by Oil asc,Price desc  ——Oil主排序,Price次排序


    delete from car ——删除全部数据
    delete from car where 条件 ——这里的条件是跟select的条件是一样的。


    update 表名 set 列名=值,列名=值..... where 条件
    update Car set Price = Price + price * 0.15 where Name like '宝马%'
    update Car set Name='300C 3.5L 商用车',Oil='9' where Code='c012'

    链接查询:
    第一步:求笛卡尔积
    select * from Info,nation
    第二步:根据两个表相对应的列,对笛卡尔积进行有效数据的筛选。
    select * from Info,Nation where Info.Nation = Nation.code
    第三步:调整显示要查询的列
    select Info.Code,Info.Name,Info.Sex,Nation.Name,Info.Birthday
    from Info,nation where Info.Nation=Nation.Code

    select * from 表名1
    join 表名2 on 表名1.列 = 表名2.列
    join 表名3 on 表名2.列 = 表名3.列
    ....
    where 查询条件

    select Car.Name,Brand.Brand_Name,Productor.Prod_Name,Car.Price
    from Car
    join brand on Car.Brand = Brand.Brand_Code
    join Productor on Brand.Prod_Code = Productor.Prod_Code
    where Price > 50

  • 相关阅读:
    Introduction to PostGIS 之加载shp数据
    缺陷管理总结篇
    对lIKE语句的优化
    数据库查询优化
    如何在 32 位版本的 ASP.NET 1.1 和 64 位版本的 ASP.NET 2.0 之间切换
    加载启动目录以外的DLL(Assembley)的3种方法
    C#中使用windows medie player控件
    在Asp.net中使用多线程
    编程控制windows防火墙的exception list.
    读书笔记Win32多线程程序设计(1)
  • 原文地址:https://www.cnblogs.com/691331894w/p/4208888.html
Copyright © 2011-2022 走看看