Get the App
SLTechnology News&Howtos  ›  Database  › 

Some sentences commonly used in mysql

Shulou Source: shulou.com Published: 2022-05-31 18:00:20 09月25日 Update

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!

Tags: Fields commonly used statements data procedures content commands learning practical deeper location function interest name practicality practical simple operation method more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MySQL Shulou Tech Info Microsoft NVidia