欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MySQL总结之SQL语句的应用

程序员文章站 2022-05-28 09:11:08
...

创建一个表:mysqlgt; CREATE TABLE students (-gt; sno CHAR(10) PRIMARY KEY,-gt; sname CHAR(8) NOT NULL,-gt; ssex CHAR

创建一个表:

mysql> CREATE TABLE students (

-> sno CHAR(10) PRIMARY KEY,

-> sname CHAR(8) NOT NULL,

-> ssex CHAR(1) NOT NULL CHECK(ssex = 'F' OR ssex = 'M'),

-> sage INT NOT NULL,

-> sdept CHAR(20) DEFAULT 'Computer'

-> )

-> ;

MySQL总结之SQL语句的应用

MySQl所支持的字符类型:

MySQL总结之SQL语句的应用

修改表结构:

mysql> ALTER TABLE students CHANGE sage sage INT UNSIGNED;

MySQL总结之SQL语句的应用

mysql> ALTER TABLE students ADD Grade1 INT NOT NULL DEFAULT '1';

MySQL总结之SQL语句的应用

删除一个字段:

mysql> ALTER TABLE students DROP Grade1 ;

表重命名:

mysql> ALTER TABLE students RENAME students2;

数据库存储引擎类型:

存储引擎:相当于一个插件,,MySQL跟存储在磁盘上的文件进行交互的接口。

*************************** 1. row ***************************

Engine: InnoDB(行级别锁 粒度比较小)

Support: YES

Comment: Supports transactions, row-level locking, and foreign keys

Transactions: YES

XA: YES

Savepoints: YES

*************************** 2. row ***************************

Engine: MRG_MYISAM

Support: YES

Comment: Collection of identical MyISAM tables

Transactions: NO

XA: NO

Savepoints: NO

*************************** 3. row ***************************

Engine: BLACKHOLE

Support: YES

Comment: /dev/null storage engine (anything you write to it disappears)

Transactions: NO

XA: NO

Savepoints: NO

*************************** 4. row ***************************

Engine: CSV

Support: YES

Comment: CSV storage engine

Transactions: NO

XA: NO

Savepoints: NO

*************************** 5. row ***************************

Engine: MEMORY

Support: YES

Comment: Hash based, stored in memory, useful for temporary tables

Transactions: NO

XA: NO

Savepoints: NO

*************************** 6. row ***************************

Engine: FEDERATED

Support: NO

Comment: Federated MySQL storage engine

Transactions: NULL

XA: NULL

Savepoints: NULL

*************************** 7. row ***************************

Engine: ARCHIVE

Support: YES

Comment: Archive storage engine

Transactions: NO

XA: NO

Savepoints: NO

*************************** 8. row ***************************

MySQL总结之SQL语句的应用