zoukankan      html  css  js  c++  java
  • 数据库 (备份、还原、分离、附加、语句)

    一、备份:将想要备份的数据库右击-任务-备份

    二、还原:

    将鼠标放到想要还原的数据库右击-任务-还原-数据库

    三、分离:

    将想要分离的数据库右击-任务-分离

    点击“确定”即可分离。

    四、附加

    右击数据库-点击附加-添加

    点击"确定"即可附加

    drop database student--删除数据库语句
    go
    create database student--创建数据库
    go--语句之间的连接
    use student--选择使用哪个数据库
    go
    sp_renamedb student,xuesheng--修改数据库的名字将student的名字改成xuesheng前面是之前的数据库名,后面是想改成的数据库名
    go
    --创建表
    create table xinxi

    (
    code int,--列名,数据类型,逗号分隔
    name varchar(20),not null,--写上not null就不能为空
    renshu decimal(18,2)
    )
    go
    --修改表,新加入列,注意与内置单词冲突的时候,列名加[]括起来
    alter table xinxi add [int] varchar(10)
    alter table xinxi add nianling int
    go
    --修改表删除一列
    alter table xinxi drop column [int]
    go
    alter table xinxi add [int] varch(10)
    --插入数据
    insert into xinxi values(1,'张三',96)
    insert into xinxi values(2,'李四',91)
    insert into xinxi values(3,'王五',69)
    insert into xinxi values(4,'赵六',76)
    insert into xinxi values(5,'田七',85)
    insert into xinxi (code,name) values(6,'重八')
    go


    go
    ---查询语句,条件查询
    select *from xinxi--查询全部
    select fenshu,name from xinxi
    select fenshu,name from xinxi where name='李四'

    select *from xinxi where fenshu between 80 and 100--范围
    --查询表中fenshu大于等于80小于等于100的所有列的数据
    update xinxi set nianling = 26 where fenshu between 80 and 100
    --更改xinxi表中fenshu在80-100之间的行的nianling列改为26
    select distinct name from xinxi
    --查询时自动去重,并不删除,针对一列去重显示
    update xinxi set nianling=23 where code = 9

    select *from xinxi where name='李四'and nianling = 26
    --查询姓名为李四并且年龄为26的信息
    select *from xinxi where name='李四'or nianling = 26
    --查询名字为李四或者年龄为26的所有数据
    select *from xinxi wHHere nianling in (21,22,23,24)
    --查询年龄在21与24之间的信息
    select *from xinxi where name in('李四','赵六')
    --查询李四与赵六的信息  

    select *from xinxi where name not in ('李四','赵六')        

    --not in查询不带李四与赵六的信息
    select *from xinxi where name like '%四%'
    --模糊查询名字里面带四的,“%四”必须是四结尾的,“四%”必须是四开头的
    --通配符%代表任意字符 like像的意思
    select *from xinxi where name like '李_'
    --下划线查询任意的一个字符
    select *from xinxi where name like '_[李四,赵六]'
    --下划线加中括号,等同于in的功能,任意一组满足就查询处理,任意一个中括号里面的值
    --按年龄排序,asc升序,desc降序,默认不写是升序
    select *from xinxi order by nianling asc
    select *from xinxi order by nianling desc
    --按年龄排序,降序,desc为后缀
    select top 3*from xinxi order by nianling
    --查找按照年龄排序之后开头的三个的所有的数据
    select top 3*from xinxi order by fenshu desc
    --查询按照分数降序排列的前三名的所有数据
    select *from xinxi where name='李四' order by fenshu desc
    --查询姓名为李四的所有数据并按照分数降序排列
    select top 1 *from xinxi where name='李四' order by fenshu desc
    --查询姓名为李四的所有数据,按照分数降序排列并选出第一名

  • 相关阅读:
    [ABC142F] Pure
    [ABC141F] Xor Sum 3
    tarjan缩点
    LoadRunner录制:事务
    LoadRunner录制:脚本调试
    linux性能监控命令
    Python 3 解析 html
    Python 3 操作json 文件
    Python 数据驱动工具:DDT
    selenium 问题:OSError: [WinError 6] 句柄无效
  • 原文地址:https://www.cnblogs.com/LCL390/p/4064058.html
Copyright © 2011-2022 走看看