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 * 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'
  • 相关阅读:
    mass Framework event模块 v9
    关于开源的网络爬虫/网络蜘蛛larbin结构分析
    socketaddr和socketaddr_in的区别于联系
    C语言中.h和.c文件解析
    [原]变参函数原理详解
    fopen和open有什么区别?
    C语言的那些小秘密之变参函数的实现
    c语言中逗号运算符和逗号表达式
    关于REST API设计的一些小经验
    Linux信号说明列表
  • 原文地址:https://www.cnblogs.com/dawasai/p/4212047.html
Copyright © 2011-2022 走看看