In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
MySQL basic statement
one。 Data definition language (DDL)
two。 Data manipulation language (DML)
three。 Data query language (DRL)
four。 Transaction Control language (TCL)
one。 Data definition language (DDL:Data Definition Language)
Modify the structure of tables and libraries. Such as create, drop, alter)
1. Create database (create database statement) create database library name
two。 Delete database (drop database statement) drop database library name
3. Create a table (create table statement) create table table name
4. Delete table (drop table statement) drop table table name
5. Modify the table structure (alter table statement)
(1)。 Modify table name
Syntax 1. Alter table table name rename new table name
Example: alter table student rename stu
Syntax 2. Rename table table name to new table name
Example: rename table student to stu
(2)。 Add column
Alter table table name add column name type
Example: alter TABLE student ADD sage int
(3)。 Delete column
Alter table table name drop column name
Example: alter table student drop sname
(4)。 Modify column type
Syntax 1. Alter table table name modify column name target type
Example: alter table student modify sid varchar (10)
Syntax 2. Alter table table name change column name target type
Alter table student change address address char (50)
(5)。 Modify column name and column type at the same time
Alter table table name change column name new column name target type
Alter table student change address add char (40)
Note:
1. The database is case-insensitive
2. Desc table name to view the structure of the table
3. The drop table statement deletes all records and table structure of the table
4. Add primary key: alter table (table name) add primary key (field name)
two。 Data manipulation language (DML:Data Manipulation Language)
(manipulate the data. Such as insert, update, delete)
1. Add data (insert into... Statement)
Syntax 1. Insert into table name (column name 1, column name 2, column name 3.) values (column name 1 value, column name 2 value, column name 3 value.)
Example: insert into stu (sid,sname,sage) values (1) Zhang San, 22)
Syntax 1. Insert into table name values (column name 1 value, column name 2 value, column name 3 value.)
Example: insert into stu values (1) Li Si', 22)
Note:
1. Syntax 1 can selectively add values for some columns, but syntax 2 needs to add all columns and add values in order.
two。 You can use the now () function to add the current time.
two。 Modify data (update...set statement)
Update table name set column name 1 = modified value, column name 2 = modified value where column name = 'value'
Example: update stu set sage=23,sname=' Li Wu 'where sid=1
Note: where represents a condition, and all data will be modified if there is no where.
3. Delete data (delete from... Statement)
(1)。 Delete all records delete from table names
(2)。 Delete the record of id=1 delete from table name where id=1
three。 Data query language (DRL:Data Retrieval Language)
(query index data. Select statement)
1. Query all data
Select * from table name
Example: Select * from stu
two。 Query specified data according to criteria
Select * from table name where column name 1 = value and column name 2 = value.
Example: Select * from stu where sid=9 and ssex=' female'
3. Query data and return the specified column
Select column name 1, column name 2 from stu
Example: Select sid,sname from stu
4. Alias (nickname) for the specified return column
Syntax 1. Select column aliases, column 2 aliases 2... From table name
Example: Select sid id,sname name from stu
Syntax 2. Select column name as alias, column name 2 as alias 2... From table name
Example: Select sid as id,sname as name from stu
5. Use comparison operators in conditions
SELECT * FROM table name where field >
< >=
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.