MySQL simple syntax (1)

Create a database

create database DATA;

Switching Database

use DATA;

Create a table

create table t1

(
ID vachar (10) Not null.
Name text,
Number char (10) Not null,
A1 Double Not null
)
## add restrictions to the column

  1. Primary key constraint. Entity integrity guarantee
    Create Table T1
    (
    user_qq VARCHAR (20 is) Not null Primary Key,
    USER_NAME VARCHAR (20 is) Not null,
    user_sex char (2) Not null,
    user_birthday datetime Not null
    )
  2. Foreign key constraint. That referential integrity
    Create Table Scores
    (
    user_qq vachar (20 is) Not null References 'Users' (userqq),
    GNO int Not null References 'games' (GNO),
    Score int Not null
    )
    . 3 Check the binding effect: domain integrity guarantee
    CREATE Games TABLE
    (
    GNO int not null CHECK (GNO> 0),
    gname VARCHAR (20) not null,
    GType VARCHAR (20) not nULL
    )
    demo found, GNO negative columns can be added, but can not enter other characters.
    4 default constraint. Domain integrity guarantee
    Create Table NE
    (
    usersex char (2) default 'M',
    usermm text Not null
    )
    . 5 auto-increment
    the CREATE Table T02
    (
    m Key AUTO_INCREMENT a PRIMARY int Not null,
    H int Not null
    )
    An auto-increment primary key must be set

Delete Data Sheet

  1. Delete the associated data tables
    drop the Table the Data, T11
    2 delete associated data tables
    when two tables have primary foreign key relationship, it should first remove the foreign key, we can lift the relationship, and then delete the primary key table.
    Releasing association (from back alter table)
    alter drop biao1 Table Foreign Key con_name
    drop table
    drop table data, t11
Published 37 original articles · won praise 10 · views 10000 +

Guess you like

Origin blog.csdn.net/OneLinee/article/details/78704676