zoukankan      html  css  js  c++  java
  • mysql 数据库表的基本操作

    1.使用数据库   use <数据库名>

    2.创建数据库表   create table <表名>();

    3.主键约束

    primary key (name)

    primary key (name,sex)

    1.一列或多列组合

    2.要求主键列的数据唯一 且不允许为空

    3.主键能够唯一标识表中一条记录

    4.外键约束

    用来在两个表之间建立连接

    1.一个或多个

    2.外键可为空

    外键作用:保证数据引用的完整性 

    5.查看数据表的基本结构

    desc/describe <表名>

    6.查看数据表详细结构

    show create table<表名G>

    7.修改数据表

    1)修改表名

    show tables

    alter table db_1 rename  tb_new;

    2)修改字段名

    alter table <表名> change <旧字段名><新字段名><新字段类型>

    3)添加字段

    alter table <表名> add <新字段名> <数据类型>

    4)删除字段

    alter table <表名> drop <字段名> 

    5)修改字段排序

    alter table <表名> modify <字段1><数据类型> first|after <字段2>

    first 将字段1 修改为表中的第一个字段;after 字段2,将字段1 插入到 字段2 后面

    6)删除表的外键约束

    alter crate

    常常感恩
  • 相关阅读:
    LintCode "Maximum Gap"
    LintCode "Wood Cut"
    LintCode "Expression Evaluation"
    LintCode "Find Peak Element II"
    LintCode "Remove Node in Binary Search Tree"
    LintCode "Delete Digits"
    LintCode "Binary Representation"
    LeetCode "Game of Life"
    LintCode "Coins in a Line"
    LintCode "Word Break"
  • 原文地址:https://www.cnblogs.com/prince365/p/11287732.html
Copyright © 2011-2022 走看看