mysql use statement

1.show databases; -- show all databases

2.show create database test_db; --Display the sql statement to create the test_db database

3.drop database test_db; -- delete the database

show create database test_db \G

4.show engines; --Display the data storage engines supported by the database

SHOW ENGINES \G; -- display after formatting

5.show variables like '%storage_engine%'; --You can view the default storage engine of the database

mysql> show variables like '%storage_engine%';
+----------------------------------+--------+
| Variable_name                    | Value  |
+----------------------------------+--------+
| default_storage_engine           | InnoDB |
| default_tmp_storage_engine       | InnoDB |
| disabled_storage_engines         |        |
| internal_tmp_disk_storage_engine | InnoDB |
+----------------------------------+--------+

6. use test_db; -- switch database or use database

7.show tables; --Display all tables under a database

8. Create table statement

 

create table tbl_bdmgm_auth_cata (
	id integer primary key auto_increment ,
	cata_name varchar(32) not null ,
	cata_level integer default 1 ,
	rec_crt_ts timestamp
);

create table tbl_dbmgm_auth_cfg (
	id integer auto_increment ,
	auth_url varchar(255) unique ,
	auth_params varchar(255) ,
	auth_code char(8) ,
	auth_name varchar(64) ,
	integer cata_id
	rec_crt_ts timestamp ,
	constraint pk_dbmgm_auth_cfg_id primary key (id),
	constraint fk_bdmgm_auth_cata_id foreign key (cata_id) references tbl_bdmgm_auth_cata(id),
	constraint un_dbmgm_auth_cfg_auth_name unique  (auth_name)
);

The constraints supported by mysql include primary key, foreign key, non-null, unique
Note : the type of foreign key must be consistent with the primary key type of the associated
table INTO tb_emp8 (name,salary) VALUES('Lucy',1000), ('Lura',1200),('Kevin',1500); 11. Use SHOW CREATE TABLE to view the details of table tb_emp1 SHOW CREATE TABLE tb_emp1; show create table tbl_bdmgm_auth_cata \G ; -- \G indicates that the create statement is displayed in the formatted format




12. Rename the data table tb_dept3 to tb_deptment3
ALTER TABLE <table name> MODIFY <field name> <data type>
ALTER TABLE tb_dept3 RENAME tb_deptment3;
13. Change the data type of the name field in the data table tb_dept1 from VARCHAR(22) to VARCHAR (30)
ALTER TABLE <table name> CHANGE <old field name> <new field name> <new data type>;
ALTER TABLE tb_dept1 MODIFY name VARCHAR(30);
14. Add an INT type after the name column in the data table tb_dept1 The field column3, the SQL statement is as follows:
ALTER TABLE <table name> ADD <new field name> <data type> [constraint conditions] [FIRST | AFTER existing field name];
ALTER TABLE tb_dept1 ADD column3 INT(11) AFTER name;
15. Delete the column2 field in the data table tb_dept1
ALTER TABLE <table name> DROP <field name>;
ALTER TABLE tb_dept1 DROP column2;
16. Modify the arrangement position of the fields
ALTER TABLE <table name> MODIFY <field1> <data type >   FIRST|AFTER <字段2>;
ALTER TABLE tb_dept1 MODIFY column1 VARCHAR(12) AFTER location;
17. Change the storage engine of the table
ALTER TABLE <table name> ENGINE=<changed storage engine name>;
ALTER TABLE tb_deptment3 ENGINE=MyISAM;
18. Delete the foreign key of the table Constraints
ALTER TABLE <table name> DROP FOREIGN KEY <foreign key constraint name>
ALTER TABLE tb_emp9 DROP FOREIGN KEY fk_emp_dept;
19.
DROP TABLE [IF EXISTS] table 1, table 2, . . . table n;
DROP TABLE IF EXISTS tb_dept2;
 
 
 
 
 
 
 

 

 

 

 

 

 

 

 

 

 

 

         

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326336477&siteId=291194637