编程知识 cdmana.com

MySQL review: create tables, MySQL data types, primary key constraints, primary key

1. Syntax for creating tables :

create table Table name ();

Create rows and columns in the table :
Name data type primary key, //primary key: This is the primary key. A table can only have one primary key , And no NULL value .( Insertion time , This Sno It can't be NULL) This is Sno It's a primary key constraint , You can modify ( A way of writing )
Name data type ( No addition not null The default value can be NULL)
Name data type

perhaps
Name data type
Name data type
Name data type primary key, // Put the primary key constraint in the last column

create table Student1(
    Sno   varchar(10)  primary key,  
     name varchar(10),
    SSex char(1),
phonenumber varchar(10)

);

 Insert picture description here
If there is no primary key constraint, an error will be reported –primary key
 Insert picture description here

also :not null What does that mean? ?

CREATE TABLE SC(
Sno VARCHAR(5) NOT NULL,
Cao VARCHAR(5) NOT NULL,
Primary key( Sno) 
);

Primary key( Sno) This means : The primary key constraint is :Sno This column .( The second way )
Sno VARCHAR(5) NOT NULL, //NOT NULL, The value of this column : You can't have null values , Insert value cannot be empty : Namely NULL;( The default is NULL value )

 Insert picture description here
You can see below :name It can be null
 Insert picture description here

mysql The data type here :

int integer Integers :1,6,11,44,865,78872 wait
VARCHAR(5) A character array amount to char :5 It means that this has 5 A character array of characters .
varchar(10): Yes 10 A character array of characters : Such as : ‘1111’, ‘helloworld’,‘fthwfw’,' written words ’ wait

2. Insert statement :( Method 1)

`

insert into student1 values('1',NULL ,NULL ,NULL);// direct values( Column name variable value , Column name variable value ...);

2. check :

Look up the variables in the table and directly define the table statement :desc Table name ;
Look up the tables in this database : Direct presentation table : show tables;( Before checking Switch database use database )

3. Run script :

mysql>source D:\dp2019\SPJ.txt// There must be :source;(cmd Inside )

版权声明
本文为[YYY speaker]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/12/202112122241265956.html

Scroll to Top