Home > Database > Mysql Tutorial > mysql学习之二:sql语句学习2_MySQL

mysql学习之二:sql语句学习2_MySQL

WBOY
Release: 2016-06-01 13:16:25
Original
1064 people have browsed it

创建数据库:

<strong><code style="padding:0px; background-color:transparent; border:0px">CREATE DATABASE stefan;</code></strong>
Copy after login

删除数据库:

<strong><code style="padding:0px; background-color:transparent; border:0px">DROP DATABASE stefan;</code></strong>
Copy after login

重命名数据库:

重命名数据库没有直接的办法。

已经不再使用的方法:

<strong><code style="padding:0px; background-color:transparent; border:0px">RENAME DATABASE stefan TO LCDB;</code></strong>
Copy after login

创建表格语法:

<strong><code style="padding:0px; background-color:transparent; border:0px">CREATE TABLE 表名称(列名称1 数据类型,列名称2 数据类型,列名称3 数据类型,....)</code></strong>
Copy after login

查看一个表格结构:

<strong><code style="padding:0px; background-color:transparent; border:0px">DESCRIBE Persons;</code></strong>
Copy after login
  

ALTER TABLE 语句用于在已有的表中添加、修改或删除列。

语法:

如需在表中添加列,请使用下列语法:

<code style="padding:0px; background-color:transparent; border:0px"><strong>ALTER TABLE table_nameADD column_name datatype</strong></code>
Copy after login

要删除表中的列,请使用下列语法:

<code style="padding:0px; background-color:transparent; border:0px"><strong>ALTER TABLE table_name DROP COLUMN column_name</strong></code>
Copy after login

注释:某些数据库系统不允许这种在数据库表中删除列的方式 (DROP COLUMN column_name)。

要改变表中列的数据类型,请使用下列语法:

<code style="padding:0px; background-color:transparent; border:0px"><strong>ALTER TABLE table_nameALTER COLUMN column_name datatype</strong></code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template