zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    面向对象三大特性之封装
    基本数据类型和引用数据类型
    面向对象三大特性之继承
    多表连接查询
    MySQL模糊查询
    MySQL数据查询入门
    Matlab 之 find()函数
    Matlab 之 字符串数组查找
    Matlab 之 数据元素访问
    让WIN10输入法变回传统模式
  • 原文地址:https://www.cnblogs.com/zhanghaiyublog/p/3583332.html
Copyright © 2011-2022 走看看