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

Practice of MySQL Foundation and sql statement practice

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

Share

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

This article mainly gives you a brief talk about MySQL fundamentals and sql sentence drills. You can check the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here, so let's go straight to the topic. I hope this article on the basis of MySQL and sql sentences practice can bring you some practical help.

Install with yum command under Linux

Practice: connect to the database 172.16.41.89

Log in to the mysql command:

Enter Mysql-u root-p and enter the password

View the database:

Show databases

Create a new database:

Create databases xiaoning default charset=utf8

Then show databases again to check that the xiaoning has been created

Statement: Create table person_info (create a table named person_info)

Create table person_info # create table person_info

(

Person_id smallint (5) unsigned auto_increment,# unsigned integer, primary key, automatic growth

Name varchar (50) not null comment 'name', # not empty, annotated as name

Country varchar (60) default 'China',# defaults to' china'

Salary decimal (10d2) default 0.00 comment 'salary', # default is 0.00, annotated as salary

Primary key (person_id) # sets person_id as the primary key

) engine=innodb default charset=utf8;# uses the InnoDB storage engine, which defaults to the utf8 character set

(the above creation statement can be copied directly)

Using the client navicat, as shown below, double-click the newly created table xiaoning, and then call up the query interface:

After clicking create query, the query edit box appears

Copy the sql statement into the edit box and run

After the creation is successful, check the library xiaoning and the table of person_info appears.

Modify table structure

Statement: alter table person_info

There are two ways to modify modify and change

Description: Col_name column name

Column_definition field type

Old_col_name original column name

New_col_name new column name

Statement format:

Modify Col_name column_definition# modifies the field type

Change old_col_name new_col_name column_definition# modifies the field name

Real fuck:

# modify the length of country field to 50 bytes using change or modify methods

Modify statement: Alter table person_info modify country varchar (50) default 'china'

Country statement: Alter table person_info change country country varchar (50) default 'china'

Add fields:

ADD col_name column_definition

Delete a field

DROP col_name

MySQL fundamentals and sql sentence practice exercise will first tell you here, for other related issues you want to know can continue to pay attention to our industry information. Our section will capture some industry news and professional knowledge to share with you every day.

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