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

Database and table operations

2025-01-16 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

-- deleting a single 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

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