zoukankan      html  css  js  c++  java
  • MySQL基础语法

    一、创建数据库

    create database oa;

    CREATE DATABASE oa; //关键字要大些

    data <–>date (不要搞混)

     

    sql server,mysql:每个项目创建一个数据库,时间1秒

    Oracle:所有项目共享一个数据库,时间要半个小时。

    二、建表

    Use oa;

     

    create table student(
    
      id int,
    
      user_name varchar(50),
    
      sex varchar(50),
    
      birt date
    
    );

    Drop table student;

    create table student(
      id int primary key auto_increment,
      user_name varchar(50),
      sex varchar(50),
      birt date
    );

    考试常考:

    DDL: (Data Definition Language) 数据库模式定义语言。CREATE、ALTER、DROP、TRUNCATE

    特点:不需要commit,不能回滚

     

    DML:(Data Manipulation Language) 数据操纵语言。

    以INSERT、UPDATE、DELETE三种指令为核心的对数据库对象运行数据访问工作的指令集。

    特点:需要commit(但mysql自动帮你commit),可以回滚

    Select(查询)

      特点:

          英语:找出年龄最大的人(重点),从学生数据中(废话)。

          中文:从学生数据中(废话),找出年龄最大的人(重点)。

    Select min(birt) from student

     

     

    这个【结果集】对应java中的ResultSet

     

    Insert (添加)

        

             单条:

             Insert into student(user_name, sex, birt) values(‘小明’,’男’,’2001-09-18’);

             多条:

     
            插入查询结果:

     

    Delete(删除):

      (理解为就是select语句,然后把select 改成delete)请注意:删除之前要三思,不要试。如果确实要试,可以先把delete 改为select ,

    看看对不对。

     

    Update(修改):

     

     

  • 相关阅读:
    Length of Last Word
    Remove Duplicates from Sorted Array II
    Sum Root to Leaf Numbers
    Valid Parentheses
    Set Matrix Zeroes
    Symmetric Tree
    Unique Binary Search Trees
    110Balanced Binary Tree
    Match:Blue Jeans(POJ 3080)
    Match:Seek the Name, Seek the Fame(POJ 2752)
  • 原文地址:https://www.cnblogs.com/zzguan/p/9173568.html
Copyright © 2011-2022 走看看