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

The most commonly used basic operations on mysql databases and data tables

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

Share

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

The following is about the basic operation of mysql database and data table. the secret of the text is that it is close to the topic. So, no gossip, let's just read the following, I believe you will benefit from reading this article on the basic operations of mysql databases and datasheets.

# # File contains: CRUD operation of database and data table # it contains: database and data table: # # character set modification of database # # Operations such as data table name, field information, etc. # # / +-- # # / / | Database operation # # / / | 1. Add-create database # # / / | 2. Delete-Delete database # # / / | 3. Change-modify the database # # / / | 3. Query-query database creation # # / +-# # 1. Database creation statement create database `liu1` character set utf8 collate utf8_general_ci # 2. Delete the database creation statement drop database if exists `liu1`; # 3. Modify the database creation statement alter database `liu1` charset = utf8alter database `liu1` collate utf8_general_ci;utf8_slovenian_ci # 4. Check the database creation statement show create database `liu1`; # # / +-- # # / / | Datasheet operation # # / / | 1. Add-create Table # / / | 2. Delete-Delete table # # / / | 3. Change-modify Table # / / | 4. Look up-View the table creation statement # # / +-# # # Field Type query # Integer # 1) tinyint 1 byte-128 127 UNSIGNED 25 characters 2) SMALLINT 2 bytes-32768 32767 UNSIGNED 6553273) MEDIUMINT 3 bytes-8388608 8388607 UNSIGNED 167772244) INT 4 bytes-2147483648 2147483647 UNSIGNED 429496729285) BIGINT 8 bytes-9223372036854775808 9223372066854775807 UNSIGNED 184467440737095516 decimal # 1) float (4 line 2) range-99.99-99.99 UNSIGNED 0-99.99 (loss of precision) # 2) decimal range-99.99-99.99 UNSIGNED 0-99.9 seconds # 1) date format: 2017-11-12 (no hours, minutes and seconds) # 2) datetime format: 2017-11-12 12 timestamp format: 2017-11-12 12:12:12 (when inserting data Default insert system current time) # multiple-choice set format: field name (attribute 1, attribute 2, attribute 3) insert into `liu1` values ('1meme 2meme4') # select * from liu1 where find_in_set (option for'1 query', 'field name for hobby query') # Radio enum (1meme 2, 3 values 4) format: field name (attribute 1, attribute 2, attribute 3) field name `liu1` values ('1') # # string # 1) char range 1-65535 bytes # 2) varchar range 1-65535 bytes (21844 Chinese characters) # 3) text # # Field Type query # # 1. Table creation statement # CREATE TABLE IF NOT EXISTS `admin` (`adminid` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'primary key ID', `adminuser` VARCHAR (32) NOT NULL DEFAULT' 'COMMENT' administrator account', `adminpass` CHAR''COMMENT' administrator password' `adminemail` VARCHAR (50) NOT NULL DEFAULT''COMMENT' administrator email', `logintime` INT UNSIGNED NOT NULL DEFAULT'0' COMMENT 'login time', `loginip` BIGINT NOT NULL DEFAULT'0' COMMENT 'login IP', `createtime`INT UNSIGNED NOT NULL DEFAULT' 0' COMMENT 'creation time', `repasssendmailtime`INT UNSIGNED NOT NULL DEFAULT'0' COMMENT 'password change time', `repasssedradint` INT UNSIGNED NOT NULL DEFAULT'0' COMMENT 'password modification random number' PRIMARY KEY (`adminid`), UNIQUE shop_admin_adminuser_adminpass (`adminuser`, `adminpass`), UNIQUE shop_admin_adminuser_adminemail (`adminuser`, `adminemail`) ENGINE=InnoDB DEFAULT CHARSET=utf8 INSERT INTO `admin` (adminuser,adminpass,adminemail,createtime) VALUES ('admin',md5 (' admin'), '857523518 Unix timestamp ()), (' admin',md5 ('admin'),' 857523518) # UNSIGNED means unsigned # PRIMARY KEY primary key can only be one primary key in a table, indicating that the data in this field cannot be duplicated and cannot be empty. # PRIMARY KEY (`adminid name`) compound primary key means that the data of two fields cannot be duplicated # UNIQUE KEY unique key can be empty in a table. And empty fields do not participate in uniqueness comparison # # 2. Delete table statement # DROP TABLE IF EXISTS `admin`; # # 3. Modify the table statement # 1. Modify the table name alter table admin1 RENAME TO admin2;#2. Modify the table character set alter table `admin2` character set utf8#3. Modify the table field length alter table `admin2` modify column adminuser varchar (32) not null default'; # 3. Insert the new field alter table `admin2` add name varchar (6) not null default''after adminid; (after adminid) # 3. Delete the new field alter table liu1 drop name;#4. Modify the table field name alter table liu1 change id id1 varchar (16) not null default''(Note: all subsequent attributes should be included) # # 4. View table creation statement # show create table admin2

Is there anything you don't understand about the basic operation of the above mysql database and data table? Or if you want to know more about it, you can continue to follow our industry information section.

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