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

How to use classification statements in SQL

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

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about how to use classified sentences in SQL. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Classification of SQL

Data definition language: DDL (DataDefinitionLanguage) for short, used to define database objects: databases, tables, columns, etc. Keywords: create,alter,drop, etc.

Data manipulation language: DML (DataManipulationLanguage) for short, used to update the records of tables in the database. Keywords: insert,delete,update, etc.

Data control language: DCL (DataControlLanguage) for short, which is used to define the access rights and security levels of the database, and to create users; keywords: grant, etc.

Data query language: DQL (DataQueryLanguage) for short, which is used to query the records of tables in the database. Keywords: select,from,where, etc.

The use of SQL statements

1. Create a MySQL database:

Createdatabase database name

Sample code:

① check localhost, then switch to the SQL editor

② enters createdatabasedb_20171227; in the SQL editor as shown in the following figure:

two。 Delete database

Basic syntax:

Delete means you don't want it, and if you don't want it, you throw away the word: drop

Dropdatabase database name

Sample code:

Special note: deleting the database is irreversible, so be careful before deleting it.

View the database

① views all databases

Word viewed: show

View all databases: showdatabases

Sample code:

② displays a specified type of database

Showdatabaseslike'db%';// queries all databases that start with db

To popularize like fuzzy queries, there are two keywords to remember:

_ (underscore): represents any character, either an or b.

% (percent sign): represents any n characters, either ab or abcd...

Create a tabl

The basic syntax for creating a data table:

Createtable data Table name (

Column name (English) column type column constraint (notnull)

)

Sample code:

Delete data tabl

Throw away: drop

Table: table

Delete data Table: droptable data Table name

Modify the data table (name of the data table)

Rename: rename

Renametable's original name, to's new name

View the data sheet

① looks at all the data tables or some kind of data

Showtableslike'_ or%'

② looks at the structure of the data table

Desc data Table name

Insert record: insert

Syntax:

Insertinto table (column name 1, column name 2, column name 3.) values (value 1, value 2, value 3.);-- insert some columns into the table

Insertinto table values (value 1, value 2, value 3.);-- insert all columns into the table

Insertinto table (column name 1, column name 2, column name 3.) valuesselect (column name 1, column name 2, column name 3.) from table

Insertinto table valuesselect*from table

Update records in the data table

Basic syntax:

Update: update

Update data table name set field (column) = updated value, field (column) = updated value where condition

Query data from a data table

① queries all data

Query: select

Select*from data Table name

Or

Select field (a column) from data table name

② queries data based on criteria (with an extra where)

Delete data from the data table (key)

Basic syntax:

Delete: delete

Deletefrom data Table name where condition

Deletefrom data Table name

Truncate data Table name

The function of both is to delete all data, but the primary key (primarykey) of the data deleted by truncate will be renumbered. The data deleted by deletefrom will continue to be numbered last time.

The above is the editor for you to share the SQL how to use classification sentences, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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