Home Database Mysql Tutorial Introducing a simple database Database tutorial (4)

Introducing a simple database Database tutorial (4)

Apr 29, 2017 pm 05:39 PM

SQL basic operations

Basic operations: CURD, that is, add, delete, modify, and query.

According to different operation objects, we can divide the basic operations of SQL into three categories: library operations, table (field) operations and data operations.

Library operation

1 Add a new database

Basic syntax: create database + database name + [library option];

Among them, the library option is used To constrain the database, it is optional (with default value). There are two types, namely:

Character set setting: charset/ character set+ specific character set, used to represent the encoding format of data storage, commonly used Character sets include GBK and UTF8, etc.

Collation set setting: collate+ specific collation set, indicating the rules of data comparison, which depends on the character set.

Example: create database TBL_ERROR_CODE charset utf8;

The name of the database cannot use keywords (already occupied characters, such as update and insert, etc.) or reserved words (which may be used in the future) , such as access and cast, etc.).

If you must use database keywords or reserved words as the database name, you must enclose it in backticks, for example:

create databaseaccesscharset utf8;
Copy after login

If you also want to use Chinese as the name of the database, Then you must ensure that the database can recognize Chinese (it is strongly recommended not to name the database in Chinese), for example:

-- method of setting Chinese names, where gbk is the default character set of the current database set names gbk;create database fructose charset utf8;123123

2 Query database

View all–> Basic syntax: show databases;

View part (fuzzy query)–> Basic syntax: show databases like 'pattern';

Among them, pattern is a matching pattern, there are two types, namely:

%: means matching multiple characters;

_: Indicates matching a single character.

In addition, when matching database names containing underscores _, you need to add a backslash \_ in front of the underscores to escape.

Example: show databases like 'TBL%'; means matching all databases starting with TBL.

View the creation statement of the database –> Basic syntax: show create database + database name;

Here, the results viewed may be different from the SQL statement we wrote, because the database SQL will be optimized before executing the SQL statement, and the system saves the optimized results.

3 Update the database

Here, please note: the name of the database cannot be modified.

The modification of the database is limited to library options, that is, character set and collation set (the collation set depends on the character set).

Basic syntax: alter database + database name + [library option];

charset/character set[=] character set;

collate[=] proofing set;

Example:

alter database TBL_ERROR_CODE charset gbk;
Copy after login

means modifying the character set of this database to gbk.

4 Delete database

Basic syntax: Drop database + database name ;

Here, please note: Before deleting the database, you should perform a backup operation first. Because deletion is an irreversible operation, do not delete the database at will.

The above is the detailed content of Introducing a simple database Database tutorial (4). For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Leak reveals key specs of Intel Arrow Lake-U, -H, -HX and -S Leak reveals key specs of Intel Arrow Lake-U, -H, -HX and -S Jun 15, 2024 pm 09:49 PM

IntelArrowLakeisexpectedtobebasedonthesameprocessorarchitectureasLunarLake,meaningthatIntel'sbrandnewLionCoveperformancecoreswillbecombinedwiththeeconomicalSkymontefficiencycores.WhileLunarLakeisonlyavailableasava

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer Jul 16, 2024 pm 09:02 PM

The expansion of the virtual market is inseparable from the circulation of virtual currency, and naturally it is also inseparable from the issue of virtual currency transfers. A common transfer error is the address copy error, and another error is the chain selection error. The transfer of virtual currency to the wrong chain is still a thorny problem, but due to the inexperience of transfer operations, novices often transfer the wrong chain. So how to recover the wrong chain of virtual currency? The wrong link can be retrieved through a third-party platform, but it may not be successful. Next, the editor will tell you in detail to help you better take care of your virtual assets. How to retrieve the wrong chain of virtual currency? The process of retrieving virtual currency transferred to the wrong chain may be complicated and challenging, but by confirming the transfer details, contacting the exchange or wallet provider, importing the private key to a compatible wallet, and using the cross-chain bridge tool

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

See all articles