What are the basic database operations?

coldplay.xixi
Release: 2020-06-29 10:55:26
Original
18273 people have browsed it

The basic operations of the database include: 1. Basic operations of the database, creating a database, viewing all information in the database, modifying the database encoding set, and removing the database; 2. Basic operations of the table, creating tables, viewing table information, and modifying Field attributes, remove tables; 3. Basic operations of fields, add fields.

What are the basic database operations?

The basic operations of the database are:

1: Basic operations of the library

Prerequisite: Connect to the database

1. Add and create the database
Use the default encoding set

create database db1; # db1为数据库名
Copy after login

Customize the encoding set

create database db1 charset="gbk";
Copy after login

2. Check and view All database information
View all databases: show databases;
Detailed information: show create database db1;

3. Change, modify the database encoding set

alter database db1 charset="utf8"
Copy after login

4. Delete and remove the database

drop database db1;
Copy after login

2: Basic operations of the table

Prerequisite: Create a table under a specific database
Enter Specified database: use db1
Determine the currently used database: select database();

1. Add, create table (field 1, type,..., field n type)

create table t1(name char,age int);
Copy after login

2. Check and view table information
View all databases: show tables;
Detailed information: show create table t1;
Table field structure information: desc t1;

3. Change, modify field attributes

alter table t1 modify name char(20);
Copy after login

Modify field name

alter table t1 change name usr char(16);
Copy after login

Modify table name

alter table t1 rename t2;
Copy after login

4. Delete, remove table

drop table t1;
Copy after login

3: Basic operations of fields

Prerequisite: Know which table is being operated on

1. Add, add fields

insert into t1(usr,age) values ("aa",18),("bb",8);
Copy after login

2.Check

select * from t1;
Copy after login

3.Change

update t1 set age=28 where usr="aa";
Copy after login

4.Delete

delete from t1 where age>8;
Copy after login

Related learning recommendations:mysql video tutorial

The above is the detailed content of What are the basic database operations?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!