博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
6.1数据库MySQL基础
阅读量:4313 次
发布时间:2019-06-06

本文共 1360 字,大约阅读时间需要 4 分钟。

1.显示当前所有数据库

show databases;

2创建数据库

create database ceshi;

3进入(使用)数据库

use ceshi;

4显示数据库中的表

show tables;

备注: 数据类型

           数字型:

                   整型: tinyint 1字节 2的8次方

                               int      4字节 2的64次方

                         decimal(m,d) 定点型 m数字的总长度

                                                                  d小数的位数

                                decimal(5,2)1.2896-1.29

                                                           999.123-999.12

                      字符型:

                            char(255)  定长字符

                            varchar(255) 变长字符

                          日期时间

                                  datetime 8字节 2018-06-01 09:05:01

                           主键:p'rimary key

                            自增长列:auto_increment

                             非空:not null

                            默认值:default值

5,建表

          需要指明 数据类型 非空

          每个表都要设置一个主键

create table Myclass(

           id int(4)not null primary key auto_increment,

           name char(20) not null,

           sex int(4) not null default"0",

           degree  decimal(16,2)

            );

6, 查看表结构

  desc  myclass;

===================

show= 显示

create= 创造

database=数据库

7插入数据

insert into myclass values(’ ’,’张三’,’ ’,98.5);

8查看表中的数据

select*from myclass;

9修改信息

 update myclass set name = '张三' where id = 1;

10删除信息

   delete from myclass where id = 1;

=============================================

alter table myclass + 语句

1 修改表名

rename as newcl;

2添加字段

 add age int(4)not null;

add pid int(4) not null first;

add selfsm char(255) not null after age;

3修改字段的名字和类型

change age newage char(20);

4修改某一字段的类型

modify column newage int(4);

5添加默认值-如果有默认值,先删除再添加

alter column newage drop default;

alter column newage set default  18;

6删除字段

drop  id;

7添加主键

add primary key(字段名);

8删除主键

drop primary key;

9删除表

drop table newcl;

show tables;

10删除数据库

drop database ceshi;

show databases;

转载于:https://www.cnblogs.com/sunhao1987/p/9122234.html

你可能感兴趣的文章
session和cookie区别与联系
查看>>
PHP 实现笛卡尔积
查看>>
Laravel中的$loop
查看>>
CentOS7 重置root密码
查看>>
Centos安装Python3
查看>>
PHP批量插入
查看>>
laravel连接sql server 2008
查看>>
Laravel框架学习笔记之任务调度(定时任务)
查看>>
laravel 定时任务秒级执行
查看>>
浅析 Laravel 官方文档推荐的 Nginx 配置
查看>>
Swagger在Laravel项目中的使用
查看>>
Laravel 的生命周期
查看>>
CentOS Docker 安装
查看>>
Nginx
查看>>
Navicat远程连接云主机数据库
查看>>
Nginx配置文件nginx.conf中文详解(总结)
查看>>
MySQL innert join、left join、right join等理解
查看>>
sdc时序约束
查看>>
NoC片上网络
查看>>
开源SoC整理
查看>>