zoukankan      html  css  js  c++  java
  • 数据库基本的的sql语句

      数据库数据类型:

        

       

       1.定义一个学生课程模式:

      create schma<模式名>authorization <用户名>

      create schema authorization wang ;  定义模式实际上定义了一个命名空间,在这个空间可以进一步定义该模式包包含的数据库对象,例如基本表、视图、索引等。

      2.建立一个课程表:

      create table course(

      Cno char(4) primary key,    //列级完整性约束条件  主码也可以由两个属性构成

      Cname  char(40),

      Cpno char(4),

      Cccredit smallint,

      foreign key cpno references Course(Cno)//表级完整性约束条件,外码,本例说明参照表和被参照表可以是同一个表

      )  

      3.修改基本表:

      (1)插入列:alter table student add s_entrance DATE;

      (2)改数据类型:alter table student alter column Sage int;

      (3)增加唯一值:alter table course add unique(Cname);

      

      4.删除基本表

      drop table Student  //默认是restrict  ,就是删除不被约束的表  若为cascade删除一切关系

      5.建立与删除索引

      create unique index Stusno on Student(Sno);

      create unique index Scno on SC(Sno ASC,Cno DESC);       //ASC升序(缺省)DESC降序

      drop index Stusno;

      6.查询

      全体学生学号与姓名:select Sno,Sname from Student;

      所有:select *from student;

      经计算的值:select sname,2004-sage from student;

      select distinct sno

      from SC

      where Grade<60;  可用and连接条件

      查询与刘晨在同一个系的学生

      select sno,sname,sdept

      from Student

      where sdept in

      (select sdept from Student where Sname='刘晨');

      增加:

      insert into student(...) values (...);

      修改元组值:

      update Student

      Set sage=22;

      where sno='  ...  ';

      删除:

      delete from sc where...;

      

      视图是从一个或几个基本表(或视图)导出的表,

      

      

      

  • 相关阅读:
    java--面向抽象编程
    java--面向接口编程
    一个网页的测试用例
    浏览器Notwork XHR被隐藏了
    在element-ui label中设置空格
    数组对象排序
    js动态替换和插入字符串
    vue-quill-editor回显时移除焦点
    vue中监听页面是否有回车键按下
    vue-quill-edito 字体倾斜加粗无效
  • 原文地址:https://www.cnblogs.com/findlisa/p/8577329.html
Copyright © 2011-2022 走看看