Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQL database and table operations

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

-- create a database

-- create a classroom database

Create database database name default character set character encoding collate collation

Eg:

Create database classroom default character set utf8 collate utf8_general_ci

-- View all databases

Show databases

-- Select a database

Use database name

Eg:

Use classroom

-- delete the database

Drop database database name

Eg:

Drop database classroom

-- create a table

-- create a class table

Create table table name (field name data type [length] attribute [non-null default value increment primary key comment]) charset=utf8,engine=innodb

Eg:

Create table class (

Id int (11) not null auto_increment primary key comment 'student number'

Name varchar (20) not null comment 'name'

Sex varchar (2) not null comment 'gender'

Age int (3) not null comment 'age'

Address varchar (255) not null comment 'Chongqing'

);

-modify the table

-- add field

Alter table table name add field name data type attribute

Eg:

Alter table class add stu_name varchar (255) null

Alter table class add birthday timest-time date

-- modify fields

Alter table Table name change Field New Field Type (Parameter) property

Eg:

Alter table class change stuname name varchar (20) not null

-- deleting a field

Alter table table name drop field

Eg:

Alter table class drop name

-- add primary key

Alter table table name add primary key (field)

Eg:

Alter table class add primary key (id)

-- modify the table name

Alter table table name rename to new name

Eg:

Alter table class rename to class_one

-- copy the table

Method 1: keys cannot be copied

Create table new table select * from old table

Eg:

Create table class1 select * from class

Method 2: full table assignment

Create table new table like old table

Eg:

Create table class1 like class

-- delete the table

-- delete the table

Drop table table name

Eg:

Drop table class1

-- Delete multiple tables

Drop table table name 1, table name 2. Table name n

Drop table class,class1,class2

-- data operation

-- insert information

-- method 1:insert...values

-- single statement

Insert into class values (21403001 'Zhang San', 'male', 20 'Chongqing')

-- multiple statements

Insert into class values

(null,' floret 1 'female', 31 'Hebei 313' female', Hebei 313 female null)

(null,' floret 1 'female', 31 'Hebei 313' female', Hebei 313 female null)

(null,' floret 1 'female', 31 'Hebei 313' female', Hebei 313 female null)

-- method 2:insert...set

Insert into class set id=null,name=' floret 1 minute recently sexualized 'female', age=32,address=' Hebei 3 minute recorder daytime nulle journal remark null

-- method 3:insert...select

Insert into class1 select * from class

-- query data

Method 1: query specific rows and columns

Select id, name from class where id

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report