zoukankan      html  css  js  c++  java
  • SQL Server复习 2013.12.16

    --新建数据库Student
    create database Student
    on primary
    (
    name='Studeng',
    filename='D:\study\course\Database\FileGroup\Student.mdf',
    size=20mb,
    maxsize=100mb,
    filegrowth=10mb
    )
    log on
    (
    name='Student_log',
    filename='D:\study\course\Database\FileGroup\Student_log.ldf',
    size=2mb,
    maxsize=5mb,
    filegrowth=1mb
    )
    go

    --创建表
    use Student
    create table S
    (
    sno nchar(5),
    sname nvarchar(3),
    ssex nchar(1),
    sbirth datetime,
    Sdept nchar(2),
    primary key (sno)
    )
    create table C
    (
    cno tinyint primary key,
    cname nvarchar(5),
    cpno tinyint,
    Ccredit tinyint
    )
    create table SC
    (
    sno nchar(5),
    cno tinyint,
    grade tinyint,
    primary key (sno, cno)
    )
    go

    --备份数据库Student
    backup database "Student" to disk='D:\study\course\Database\BackUp\Student.bak'

    --删除表
    use Student
    drop table C,S,SC
    go

    --删除数据库
    use master
    drop database Student
    go

    --还原数据库
    use master
    restore database "Student" from disk='D:\study\course\Database\BackUp\Student.bak'
    go

    --为SC表添加外键约束
    use Student
    alter table SC
    add constraint fk_sno foreign key(sno) references S(sno)
    alter table SC
    add constraint fk_cno foreign key(cno) references C(cno)
    go

    --删除S表中创建的约束或者索引
    use Student
    alter table S
    drop constraint PK_sno
    alter table S
    drop constraint DF_S_ssex
    alter table S
    drop constraint uk_sname
    alter table S
    drop constraint ck_sbirth
    alter table S
    drop constraint IX_birth
    go

    --创建一个ssex_rule规则,将其绑定到S表的ssex性别字段上
    use Student
    go
    create rule ssex_rule
    as @ssex in (N'男', N'女')
    go
    --将该规则绑定到S表的ssex性别字段上
    use Student
    exec sp_bindrule 'ssex_rule', 'S.ssex'
    go

    --验证
    use Student
    insert into S(ssex, sno)
    values(N'中', N'00001')
    go

    use Student
    insert into S(sno, ssex, sname)
    values(N'00002', N'中', N'张三')
    go

    --删除ssex_rule规则
    use Student
    exec sp_unbindrule 'S.ssex'
    go

    --创建一个ssex_def默认对象,将其绑定到S表的ssex性别字段上,使其默认值为男
    use Student
    go
    create default ssex_def as N'男'
    go
    exec sp_bindefault 'ssex_def', 'S.ssex'
    go
    --解除默认对象绑定
    exec sp_unbindefault 'S.ssex'
    go
    --删除ssex_def
    drop default ssex_def


    use Student
    select * from S
    go

    mysql查看表结构命令,如下:

    desc 表名;
    show columns from 表名;
    describe 表名;
    show create table 表名;

    use information_schema
    select * from columns where table_name='表名';

    顺便记下:
    show databases;
    use 数据库名;
    show tables;

  • 相关阅读:
    基于centOS7→nginx安装
    基于centOS7→tomcat安装配置
    chmod、acl权限
    解决终端SSH连接服务器一段时间不操作之后卡死的问题
    客户端加域失败,提示“找不到网络名”解决的方案
    将博客搬至CSDN
    Qt on android 蓝牙开发(控制小车)
    qt程序运行时的错误error:undefined reference to `_imp___ZN10QTcpSocketD1Ev'
    QT 实现在QLabel上画图
    linux文件访问权限(像rw-r--rw-是什么意思)
  • 原文地址:https://www.cnblogs.com/starlitnext/p/3477345.html
Copyright © 2011-2022 走看看