【Mysql 表约束(基础6)】教程文章相关的互联网学习教程文章

mysql5.7基础 drop database if exists... 删除数据库前判断它是否存在【代码】

show databases; +--------------------+ | Database | +--------------------+ | information_schema | | @@@@ | | database | | mysql | | newbases | | performance_schema | | test | +--------------------+ 7 rows in set (0.00 sec)mysql> drop database if exists aaa; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> drop database if...

mysql5.7基础 create...default 创建有默认值的字段

mysql> create table t2(2 -> name varchar(9) default ‘hello‘3 -> );4 Query OK, 0 rows affected (0.08 sec)5 6 mysql> desc t2;7 +-------+------------+------+-----+---------+-------+8 | Field | Type | Null | Key | Default | Extra |9 +-------+------------+------+-----+---------+-------+ 10 | name | varchar(9) | YES | | hello | | 11 +-------+------------+------+-----+------...

mysql5.7基础 default 向有默认值的字段中添加数据

desc t1; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(10) | YES | | 未登记 | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)mysql> insert into t1 (id,name) value...

mysql5.7基础 select...order by...asc 按照一个字段进行升序排序

select * from t1; +------+-------+ | id | name | +------+-------+ | 4 | Hello | | 2 | World | | 1 | nihao | | 3 | nihao | | 100 | nihao | +------+-------+ 5 rows in set (0.00 sec)mysql> select * from t1 order by id asc; +------+-------+ | id | name | +------+-------+ | 1 | nihao | | 2 | World | | 3 | nihao | | 4 | Hello | | 100 | nihao | +------+-------+ 5 rows in s...

mysql5.7基础 limit 从第二条开始取三条数据

select * from t1; +------+-------+ | id | name | +------+-------+ | 4 | Hello | | 2 | World | | 1 | nihao | | 3 | nihao | | 100 | nihao | +------+-------+ 5 rows in set (0.00 sec)mysql> select * from t1 limit 1,3; +------+-------+ | id | name | +------+-------+ | 2 | World | | 1 | nihao | | 3 | nihao | +------+-------+ 3 rows in set (0.00 sec)mysql>/* 在数据库中第一条的...

JDBC连接MySQL数据库基础【代码】

import java.sql.Connection;2 import java.sql.DriverManager;3 import java.sql.SQLException;4 5 public class ExampleDatabase {6 //定义MySQL的数据库驱动程序7 public static final String DBDRIVER = "com.mysql.jdbc.Driver";8 //定义MySQL数据库的连接地址9 public static final String DBURL = "jdbc:mysql://localhost:3306/test"; 10 //MySQL数据库的连接用户名 11 public static final Strin...

JavaSE基础篇—MySQL基础知识点

MySQL是一种关系数据库管理系统,是一种开源软件。可搭配PHP和Apache可以有更好的性能,也可以工作在众多的平台上。Orcale是一个数据库创建多个用户,MySQL是一个用户创建多个数据库。安装注意事项:端口:3306;默认用户:root;字符集:设置为gbk或者utf-8;安装时可以启用远程登陆,创建匿名用户;可以安装图形化界面,方便操作 MySQL列的类型:数值类型:smallint():占2个字节int():占4个字节,integer是int的同义词,也是占4个...

mysql5.7基础 alter database...charset=... 修改数据库的字符编码 将utf8改为gbk

show create database newDB; +----------+----------------------------------------------------------------+ | Database | Create Database | +----------+----------------------------------------------------------------+ | newdb | CREATE DATABASE `newdb` /*!40100 DEFAULT CHARACTER SET utf8 */ | +----------+------------------------------------------------...

mysql5.7基础 create 使用反引号创建以关键字为名的字段

create table myT1(-> `null` int-> ); Query OK, 0 rows affected (0.08 sec)mysql> desc myt1; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | null | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 1 row in set (0.00 sec) mysql,关系型数据库管理系统...

mysql5.7基础 create database... 创建的数据库的名字是 关键字、特殊字符,用反引号【代码】

create database database; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘datab ase‘ at line 1mysql> create database @@@@; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘@@@@‘at lin...

mysql5.5基础 describe 显示表的结构

describe student; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | stuId | int(11) | YES | | NULL | | | stuName | varchar(15) | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 2 rows in set (0.04 sec) mysql,关系...

mysql5.7基础 show create database... 查看一个数据库用的是什么字符编码

show create database newbases; +----------+-------------------------------------------------------------------+| Database | Create Database |+----------+-------------------------------------------------------------------+| newbases | CREATE DATABASE `newbases` /*!40100 DEFAULT CHARACTER SET utf8 */ |+----------+-------------------------------------...

mysql5.7基础 drop databases... 删除数据库

show databases; +--------------------+ | Database | +--------------------+ | information_schema | | @@@@ | | database | | mysql | | newbases | | newdb | | performance_schema | | test | +--------------------+ 8 rows in set (0.00 sec)mysql> drop database newdb; Query OK, 0 rows affected (0.58 sec)mysql> show database...

mysql5.5基础 使用win7的cmd连接mysql数据库【图】

版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Users\Administrator>f:F:\>cd F:\wamp\mysql\binF:\wamp\mysql\bin>mysql -h 127.0.0.1 -u root -p -P 3306 Enter password: ***** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.27 MySQL Community Server (GPL)Copyright (c) 2000, 2011, Oracle and/or its affiliates. All righ...

mysql5.5基础 drop table... 删除一个表或者多个表【代码】

show tables; +--------------------+ | Tables_in_newbases | +--------------------+ | student | +--------------------+ 1 row in set (0.00 sec)mysql> drop table student; Query OK, 0 rows affected (0.07 sec)mysql> show tables; Empty set (0.00 sec)mysql> 删除多个表 的代码及效果mysql> show tables; +--------------------+ | Tables_in_newbases | +--------------------+ | myt1 | |...