MySQL 建表

在test数据库创建players表

create table  if not exists test.players(
    playerno    integer not null PRIMARY KEY,
    `name`      char(15) not null,
    initials    char(3) not null,
    birth_date  date  null,
    sex         char(1) not null,
    joined      smallint not null,
    street      varchar(30) not null,
    houseno     char(4) null,
    postcode    char(6) null,
    town          varchar(30) not null,
    phoneno     char(13) null,
    leaguno     char(4) unique)

语法

<create table statement> ::=
    CREATE [ TEMPORARY ] TABLE [ IF NOT EXISTS ]
        <table specification> <table structure>[ <table option>... ]

<table specification> ::= [ <database name> . ] <table name>

<table structure> ::= <table schema>

<table schema> ::=
    ( <table element> [ , <table element> ]... )

<table element> ::=
    <column definition> |
    <table integrity constraint> |
    <index definition>

<column definition> ::=
    <column name> <data type> [ <null specification> ]
        [ <column integrity constraint> ]

<null specification> ::= [ NOT ] NULL

<column integrity constraint> ::=
    PRIMARY KEY |
    UNIQUE [ KEY ] |
    <check integrity constraint>

<table integrity constraint> ::=
    <primary key> |
    <alternate key> |
    <foreign key> |
    <check integrity constraint>

<table option> ::=
    ENGINE = <engine name> |
    TYPE = <engine name> |
    UNION = ( <table name> [ , <table name> ]... ) |
    INSERT_METHOD = { NO | FIRST | LAST } |
    AUTO_INCREMENT = <whole number> |
    COMMENT = <alphanumeric literal> |
    AVG_ROW_LENGTH = <whole number> |
    MAX_ROWS = <whole number> |
    MIN_ROWS = <whole number> |
    [ DEFAULT ] CHARACTER SET { <name> | DEFAULT } |
    [ DEFAULT ] COLLATE { <name> | DEFAULT } |
    DATA DIRECTORY = <directory> |
    INDEX DIRECTORY = <directory> |
    CHECK_SUM = { 0 | 1 } |
    DELAY_KEY_WRITE = { 0 | 1 } |
    PACK_KEYS = { 0 | 1 | DEFAULT } |
    PASSWORD = <alphanumeric literal> |
    RAID_TYPE = { 1 | STRIPED | RAID0 } |
    RAID_CHUNKS = <whole number> |
    RAID_CHUNKSIZE = <whole number> |
    ROW_FORMAT = { DEFAULT | DYNAMIC | FIXED | COMPRESSED }

1 删除表

语法

<drop table statement> ::=
    DROP [ TEMPORARY ] { TABLE | TABLES } [ IF EXISTS ]
    <table specification> [ , <table specification> ]...
    [ CASCADE | RESTRICT ]

删除 players

DROP TABLE PLAYERS

2 修改表名称

语法

<rename table statement> ::=
    RENAME { TABLE | TABLES } <table name change>
        [ , <table name change> ]...

<table name change> ::= <table name> TO <table name>

将 PLAYERS 改名为 TENNIS_PLAYERS

rename table players to tennis_players

将 PLAYERS 改名为 TENNIS_PLAYERS,COMMITTEE_MEMBERS 改名为 MEMBERS

RENAME TABLES PLAYERS TO TENNIS_PLAYERS,COMMITTEE_MEMBERS TO MEMBERS
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用MySQL数据库的建表语句来创建表。以下是一个示例的MySQL建表语句: CREATE TABLE 名 ( 列1 数据类型, 列2 数据类型, 列3 数据类型, ... ); 其中,名是您要创建的的名称,列1、列2、列3等是您要在中创建的列的名称,数据类型是指定每个列的数据类型。 例如,如果您要创建一个名为"employees"的,其中包含名字、年龄和工资三个列,您可以使用以下建表语句: CREATE TABLE employees ( name VARCHAR(50), age INT, salary DECIMAL(10,2) ); 在上面的例子中,name列的数据类型是VARCHAR(50),示存储最多50个字符的文本;age列的数据类型是INT,示存储整数;salary列的数据类型是DECIMAL(10,2),示存储最多10位数的带有两位小数的十进制数。 根据您的需求和的结构,您可以使用类似的语法来创建适合您的MySQL建表语句。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [常用mysql数据库配置文件](https://download.csdn.net/download/zslsh44/88278582)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Excel生成MYSQL建表语句](https://download.csdn.net/download/u014624447/13781003)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值