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

Addition, deletion, modification and query of MySql database

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1. Create a database: CREATE DATEBASE database name; example: create database aa

2. View the list of databases: SHOW DATABASES

3. Choose to enter the database: USE database; example: use aa;4, create database table: CREATE TABLE table name (field 1 data type [field properties | constraints] [index] [comments], field 2 data types [field properties | constraints] [comments] …) Example: create table C02 ("name" CHAR (24), "age" INT (4)); 5. View the list of data tables: show tables;6, view the definition fields in the table: DESCRIBE table name or DESC table name example: describe aa;desc aa

7. Commonly used field attribute constraints: non-null constraint NOT NULL if a field is not allowed to be empty, you need to set a NOT NULL constraint. The default constraint DEFAULT assigns a field a default value. If the field is not assigned a value, the value is the default value. For example, if there are most boys in the student table, the gender default value can be set to "male" unique constraint UNIQUE KEY setting field is unique. Null is allowed, but only one null primary key constraint PRIMARY KEY sets this field as the primary key of the table, and can be used as the only tag for the table record foreign key constraint FOREIGN KEY is used to establish a relationship between the two tables. You need to specify which field references the primary table to automatically grow AUTO_INCREMENT to set this field to self-increment field. By default, each entry increments 18 and inserts data into the data table: INSERT INTO table name [(field name list)] VALUES (values list) Example: insert into cc ("id", "name", "age") values ('12-year-old, 'Zhang San', '19')

Insert multiple rows of data: INSERT INTO table name (field name list) VALUES (values list), (values list)... ; example: insert into cc values ('13th century,' Lisi', '20'), (' 14,14, 'Wang er,' 30')

Modify table name: ALTER TABLE old table name RENAME new table name; example: alter table c02 rename c01; modify field name and data type that already exist in the table: ALTER TABLE table name CHANGE field name new data type attribute; example: alter table C02 change "date of birth"× × × number" INT (18) NOT NULL Add a new field to the existing field: ALTER TABLE table name ADD field name data type attribute; Note: the data type refers to the modified data type, which is consistent with the original data type if no modification is needed, but the data type cannot be empty. Example: alter table CO2 add "position" CHAR (24); alter table CO2 add "payroll" INT (24); delete a field from the table: ALTER TABLE table name DROP field name; example: alter table CO2 drop age; update data record: UPDATE table name SET column name = update value [WHERE update condition] Note: SET can be followed by multiple "column name = update value" has modified the value of multiple data columns, not limited to one, different columns are separated by commas example: update C02 set name = "Li Si" where name = "Zhang San"; data query SELECT * FROM table name [WHERE conditional statement]; Note: if there is no where conditional statement, then all the contents of the table will be viewed by default. Example: select * from c02; delete data records: DELETE FROM table name [WHERE]; Note: if there is no where condition, delete all data records in the database. Example: delete from c02; delete table: DROP TABLE table name; example: drop table c02; delete database: DROP DATABASE database name; example: drop database aa

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

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report