zoukankan      html  css  js  c++  java
  • 常用SQL语句 DoTop

    1、创建表
      基本语句格式:
      create table <表名> (<列名> <数据类型> [列级完整性约束]
                [,<列名> <数据类型> [列级完整性约束]
                ......
                [,<列名> <数据类型> [列级完整性约束])
      例:

    create table Student(
    Sno char(9) primary key,/*列级完整约束条件,Sno主键*/
    Sname char(20)  unique,/*唯一标识*/
    Ssex char(2),
    Sage smallint ,
    Sdept char(20)
    )
    
    create table Course
    (Cno char(4) primary key,
    Cname char(40),
    Cpno char(4),
    Ccredit smallint,
    foreign key (Cpno) references Course(Cno)
    /*表级完整约束条件,Cpno外码被参照表是Course,被参照列是Cno*/
    )
    
    create table SC
    (Sno char(9),
    Cno char(4),
    Grade smallint,
    primary key (Sno,Cno),
    foreign key(Sno) references Student(Sno),
    foreign key(Cno) references Course(Cno)
    )
    

    2、修改表
    基本语句格式:
      alter table <表名>
      [add <新列名> <数据类型> [完整性约束]]
      [drop column <列名>

      [drop<完整性约束名>]
      [alter column <列名> <数据类型>]
     
    例:

    alter table Student add  S_entrance date;/*添加列*/
    alter table Student alter column Sage int;/*修改数据类型*/
    alter table Course add unique(Cname);/*增加约束条件*/
    alter table Student drop column S_entrance/*删除列*/
    alter table Course drop FK__SC__Cno__145C0A3F;/*删除完整性约束*/

    3、删除基本表
    格式:
      drop table <表名>

    4、查询语句
    基本格式:
      SELECT   [ ALL  |  DISTINCT ]  <字段表达式1>  [,…]
      FROM  <表名1>  [,<表名1>  [,...] ]
      [ WHERE  <筛选条件表达式>  ]
      [ GROUP  BY  <分组表达式> [  HAVING  <分组条件表达式> ] ]
      [ORDER  BY  <字段>  [  ASC  |  DESC  ] ]

  • 相关阅读:
    面试题目以及注意事项
    jQuery Ajax 实例 ($.ajax、$.post、$.get)
    前端知识大全
    jquery实现2级联动
    [转]那些年我们一起清除过的浮动
    使用kubeadm在CentOS上搭建Kubernetes1.14.3集群
    企业优秀运维人员20道必会iptables面试题
    通过nginx日志利用shell统计日pv和uv
    php访问mysql接口pdo-mysql安装
    何查看已经安装的nginx、apache、mysql和php的编译参数
  • 原文地址:https://www.cnblogs.com/zizaisuixin/p/2587127.html
Copyright © 2011-2022 走看看