• sqlserver练习


    create database sqlserver
    use sqlserver
    --创建学校
    create table school(id int primary key ,name varchar(255) default '耶鲁大学')
    insert into school(id) values(1)
    select * from school
    --创建年级
    use sqlserver
    truncate from table school/**truncate好像输出表了 待验证**/
    delete from  school
    create table class(id int constraint PK_class primary key ,name varchar(255),sid int constraint FK_class_school foreign key(sid) references school(id))
    select * from class
    insert into class values(1,'一班',1)


    --创建学生
    create table student(id int ,name varchar(255),age int,cid int)
    alter table student alter column id int not null
    go
    alter table student add constraint PK_student primary key(id)
    go
    alter table student  add check(age>0)
    go
    alter table student add constraint FK_student_class foreign key(cid) references class(id)
    go


    insert into student values(1,'Jack',23,1)
    ---联合查询
    select school.name as 学校 , class.name as 年级,student.name as 姓名 ,student.age 年龄
    from student student left join class class on student.cid=class.id left join school school on class.sid=school.id
    ---把结果放在一行
    select name as 信息 from school
    union all
    select name from class
    union all 
    select name from student
    union all
    select convert(varchar(255),age) from student


    --查询表的信息
    select * from sysobjects where id= object_id('school')
    select * from syscolumns 


    --删除数据库
    use master
    drop database sqlserver
  • 相关阅读:
    快速幂 快速乘法
    扩展欧几里得学习笔记
    求逆序数数目(树状数组+离散化)
    隐式图的遍历
    随机数生成
    推倒重来
    动态规划初步
    子集生成
    东大oj1155 等凹函数
    P1278 单词游戏
  • 原文地址:https://www.cnblogs.com/zhanghaiyublog/p/3583332.html
Copyright © 2020-2023  润新知