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

Some sentences commonly used in mysql

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "some sentences commonly used in mysql". Friends who are interested may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "some sentences commonly used in mysql".

Create a tabl

Create TABLE emp (

Id INT (10) unsigned NOT NULL AUTO_INCREMENT

Emp_no VARCHAR (10) NOT NULL

Emp_name VARCHAR (50) NOT NULL

Emp_sex CHAR (1) default null

Emp_salary DOUBLE (10dint 2) default NULL

Birthday Date default null

Entry_date TIMESTAMP (8)

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8

Insert data

Insert into emp (emp_no,emp_name,emp_sex,emp_salary,birthday) values ('1001, 2004-09-23')

Add table field number after cityId

Alter table emp ADD number INT (10) after emp_name

Modify the field name definition of the table

Alter table emp change emp_name emp_namedd VARCHAR (55)

Modify the definition location of the fields of the table

Alter table emp modify emp_name VARCHAR (20) default 'zhangsan'

Delete fields from a table

Alter table emp drop emp_name

Delete tabl

Drop table emp

Clear the table data

Truncate table emp

Get the table structure

Desc emp

This is used to optimize the table. This command merges the fragments in the table and eliminates the waste of space caused by deletions or updates. This command only works on MyISAM BDB,InnoDB.

OPTIMIZE TABLE emp

Creation process: insert 10000 pieces of data into table emp

Create PROCEDURE createEmpData ()

BEGIN

Set @ Xero1

Loop1:LOOP

Set @ x = @ x + 1

If @ x = 10000 THEN

LEAVE loop1

End IF

Insert into emp (emp_no,emp_name,emp_sex,emp_salary,birthday) values ('1001, 2004, 09, 23, 2004)

End loop loop1

END

Calling procedure

Call createEmpData

Delete process

Drop PROCEDURE createEmpData

At this point, I believe you have a deeper understanding of "some sentences commonly used in mysql". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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