MySQL数据库(24)

来源:互联网 发布:mac air怎么下载office 编辑:程序博客网 时间:2024/06/05 04:39

1.创建:CREATE DATABASE [IF NOT EXISTS] 数据库名;
   删除:DROP DATABASE[IF EXISTS] 数据库名;

   显示:SHOW DATABASES;

   使用/切换:USE 数据库名;

2.修改数据表:
    修改表名:alter table 旧表名 rename 新表名;
    添加字段:alter table 表名 add 字段名 列类型 [属性];
    修改字段:alter table 表名 change 旧字段名 新字段名 列类型 [属性];
    删除字段:alter table 表名 drop 字段名;

3.查看表:desc 表名;
4.添加主键
   alter table 表名 add constraint 主键名
   primary key 表名(主键字段);
5.添加外键
   alter table 表名 add constraint 外键名
   foreign key(外键字段)
   references 关联表名(关联字段);

6.更新数据
   update 表名
   set 字段1=值1,字段2=值2……
   [where 条件];
7.删除数据:
   delete from 表名 [where 条件];
   truncate table 表名;——一次性都删除

0 0
原创粉丝点击