zoukankan      html  css  js  c++  java
  • 一些不是很常用的SQL语句

    -- 创建一个名为"book"的用户数据库,其主文件大小为120MB,初始大小为55MB   
    --
     文件大小增长率为10%,日志文件大小为30MB,初始大小为12MB,文件增长增量为3MB   
    --
     文件均存储在 "D:\数据库\" 下   
    create database book   
    on primary  
    (   
        name
    =book,   
        filename
    ='d:\数据库\book.mdf',   
        size
    =55,   
        maxsize
    =120,   
        filegrowth
    =10%   
    )   
    log on  
    (   
        name
    =book_log,   
        filename
    ='d:\数据库\book.ldf',   
        size
    =12,   
        maxsize
    =30,   
        filegrowth
    =3   
    )   
      
    -- 查看数据库'book'的信息   
    sp_helpdb 'book'  
      
    -- 扩充数据库,必须大于原数据库的大小   
    use book   
    go   
    alter database book   
    modify 
    file   
    (   
        name
    =book,   
        size
    =50   
    )   
      
    -- 缩减数据库   
    use book   
    go   
    dbcc shrinkdatabase ('book')   
      
    -- 更改数据库为"只读",取消"只读"则是false   
    exec sp_dboption 'book','read only',true  
      
    -- 改成单用户模式   
    exec sp_dboption 'book','single user',true  
      
    -- 数据库更名,得先把数据库改为单用户模式   
    exec sp_dboption 'book','single user',true  
    exec sp_renamedb 'book','shu'  
    exec sp_dboption 'shu','single user',false  
      
    -- 删除数据库,得先停止对该数据库的使用   
    use master   
    go   
    drop database shu   
      
    -- 创建表   
    use book   
    create table author   
    (   
        id 
    int primary key identity(1,1),  -- 主键,自增   
        name nvarchar(20not null,  -- 非空   
        sex nvarchar(1default(''check(sex='' or sex=''-- 默认'男',约束该字段只能是'男'或'女'   
    )   
      
    -- 查看表信息   
    exec sp_help author   
      
    -- 显示SQL语句的查询计划   
    use northwind   
    go   
    set showplan_all on  
    go   
    select * from customers where customerid='BLONP'  
    go   
    set showplan_all off  
      
    -- 显示SQL语句的所花费磁盘活动量   
    use northwind   
    go   
    set statistics io on  
    go   
    select * from customers where customerid='BLONP'  
    go   
    set statistics io off 
  • 相关阅读:
    centos 7更新yum源与更新系统
    IE报错:模块"scrrun.dll"已加载,但对DllRegisterServer的调用失败,错误代码为0x80004005
    translate和replace的区别
    windows10降低IE版本
    powerDesigner 报Unable to connect SQLState=08004 解决方法
    as php交互
    帝国cms模板list.var使用程序代码
    如何用PHP代码实现灵动标签的功能
    【转】PHP调试利器XDebug的安装与使用
    一个不错的资料大全 amfphp
  • 原文地址:https://www.cnblogs.com/kingfly/p/1570423.html
Copyright © 2011-2022 走看看