• 《数据库》-基础


    -------创建数据库----------
    create database ceshi
    on primary(
      name = 'ceshi',
      filename = 'F:数据库ceshi.mdf',
      size = 5mb,
      filegrowth = 1mb
    )
    log on(
      name = 'ceshi_log',
      filename = 'F:数据库ceshi_log.ldf',
      size = 1mb,
      filegrowth = 10%
    )
    -------创建表--------------
    use ceshi;

    create table ClassInfo(
      cId int not null primary key identity(1,1),
      cTitle nvarchar(10)
    )

    create table StudentInfo(
      [sId] int not null primary key identity(1,1),
      sName nvarchar(10) not null,
      sGender char(6),
      sBirthday datetime,
      sPhone char(11),
      sEmail varchar(20),
      cid int not null,
      foreign key(cid) references ClassInfo(cid)
    )

    -------查看表--------------
    select * from ClassInfo
    select * from StudentInfo
    --------添加约束-------------
    ------手动删除一列------
    alter table StudentInfo
    drop column QQ
    ------手动添加一列-----
    alter table StudentInfo
    add sPhone char(11)
    ------手动修改列的数据类型----
    alter table StudentInfo
    alter column sPhone char(12)
    ------为ClassInfo添加一个主键约束---------
    alter table ClassInfo
    add constraint PK_cid primary key(cId)
    ------为StudentInfo添加外键约束---------
    alter table StudentInfo
    add constraint FK_sCid foreign key(cid) references ClassInfo(cid)
    ------非空约束,为sGender增加一个非空约束---
    alter table StudentInfo
    alter column sGender char(6) not null
    ------为sName增加一个唯一约束--------
    alter table StudentInfo
    add constraint UQ_sName unique(sName)
    ------为性别增加一个默认约束,默认为'男'---
    alter table StudentInfo
    add constraint DF_sGender default('男') for sGender
    ------为年龄增加一个检查约束:年龄必须在0-120岁之间
    alter table StudentInfo
    add constraint CK_sAge check(sAge >= 0 and sAge <= 120)
    ------删除约束--------
    alter table StudentInfo
    drop constraint [FK__StudentInfo__cid__1273C1CD]

    -------对数据增删改查------
    -----增-------
    insert into StudentInfo
    values('张三','男',1996-2-1,'2312@qq.com',1,'13223455432')
    -----查-------
    select * from StudentInfo
    -----删-------
    delete from StudentInfo where sName = '张三'

    truncate table StudentInfo ---删除表内容,并释放空间

    drop table StudentInfo ---删除表内容和结构

    -----改-------
    update StudentInfo set sName = '李四' where sId = 4

  • 相关阅读:
    VSCode编辑器在开发时常用的插件
    表单的数据校验规则及使用记录
    Vuex的插件保持状态持久化
    VueCli3项目中模拟数据及配置代理转发
    CSS 模块化
    Vue中静态地址的使用方式
    Vue中自动化引入样式及组件样式穿透
    Vue中的全局混入或局部混入
    让IE6 IE7 IE8 IE9 IE10 IE11支持Bootstrap的解决方法
    刚学玩原生JS,自己写了一个小游戏,希望在以后能不断地进步加以改善
  • 原文地址:https://www.cnblogs.com/lg804721251/p/7753927.html
Copyright © 2020-2023  润新知