zoukankan      html  css  js  c++  java
  • S2 第二章数据库的实现

     实现增删改查代码
    1 select * from student 2 --增加数据 3 insert into student (name,banji,xuehao) 4 values('老六',1422,444) 5 6 --修改数据 7 update student set banji=1239 8 where name='老六' 9 10 --查询数据 11 select name,banji from student 12 where banji>=1300 13 order by name 14 15 --删除数据 16 delete from student 17 where xuehao>=444 18

    --创建数据库
     create database Myday
    on primary
    (
    name='Myday1',
    filename='D:创建数据库Myday1.mdf',
    size=5mb,
    maxsize=100mb,
    filegrowth=15%
    )
    log on
    (
    name='Myday2',
    filename='D:创建数据库Maday2.ldf',
    size=2mb,
    filegrowth=1mb
    )
    go
    
    --查看以创建数据库
    use master
    go
    select*from sysdatabases
    
    --删除数据库并创建一个新的数据库
    use master
    go
    if exists(select*from sysdatabases
    where name='Myday1')
    drop database Myday1
    create database Myday1
    
    --创建表
    use Myday1
    go
    create table Student /*-创建学生信息表-*/
    (
    StudentNo int not null,             --学号,非空(必填)
    LoginPwd nvarchar(20)not null,      --
    StudentName nvarchar(20)not null,   --学生姓名,非空(必填)
    Sex bit not null,                   --性别,取值0或1
    GradeId int not null,               --年级编号
    Phone nvarchar(50) null,            --联系电话,允许为空,即可选输入
    Address nvarchar(255) null,         --住址,允许为空,即可选输入
    BornDate datetime not null,         --出生日期
    Email nvarchar(50) null,            --邮箱账号,允许为空,即可选输入
    IdentityCard varchar(18) not null   --身份证号
    )
    go
    --添加主键约束
    alter table Student
    add constraint PK_Student primary key (Student)
    
    --添加唯一约束
    alter table Student
    add constraint UQ_Student1 unique (Student1)
    
    --添加默认约束
    alter table Student
    add constraint DF_Student2 default('默认') for Student2
    
    --添加检查约束
    alter table Student
    add constraint CK_Student3 check (Student3>=100)
    
    --添加外键约束
    alter table Student
    add constraint Student4
    foreign key(Student)references Student(Student)
    
    
    
    
    
  • 相关阅读:
    ural(Timus) 1019 Line Painting
    ACMICPC Live Archive 2031 Dance Dance Revolution
    poj 3321 Apple Tree
    其他OJ 树型DP 选课
    poj 3548 Restoring the digits
    ACMICPC Live Archive 3031 Cable TV Network
    递归循环获取指定节点下面的所有子节点
    手动触发asp.net页面验证控件事件
    子级Repeater获取父级Repeater绑定项的值
    没有列名的数据绑定
  • 原文地址:https://www.cnblogs.com/lizeyang/p/5250500.html
Copyright © 2011-2022 走看看