Mysql basic syntax summary, mysql basic syntax

Source: Internet
Author: User

Mysql basic syntax summary, mysql basic syntax
# Creating a table
Create database mytest
USE mytest
Create table userInfo (
UserId int primary key AUTO_INCREMENT not null, # auto_increment is automatically increased
UserSex INT (4) DEFAULT '0', # DEFAULT gender is 0
UserAges DOUBLE () not null, # The salary is of the double type.
UserName VARCHAR (20) not null,
UserPwd VARCHAR (20) NOT NULL
);




# Insert data to a table
Insert into userInfo VALUES ('', 123456, 'zhang san', '000000'), ('', 123456, 'Li si', '000000, 'wang 5', '123 ')


# Querying data in a table
SELECT * FROM userInfo;


# Deleting a table
Drop table userInfo;
 
# Query table name
DESC userInfo;


# View the first two rows of data in table userInfo
SELECT * FROM userInfo order by userId LIMIT 0, 2;


# View the first two rows of data in table userInfo (same as above)
SELECT * FROM userInfo LIMIT 0, 2;


# Delete a record numbered 1 in Table userInfo
Delete from userInfo WHERE userId = 1;


# Modify the record numbered 1 in Table userInfo
UPDATE userInfo SET userWages = 4500 WHERE userId = 2;


# Add a field userAge to table userInfo, whose type is int (100)
Alter table userInfo ADD userAge INT (100 );


# Change the userInfo name of the table to stuClass
Rename table userInfo TO stuInfo;


# Modifying the userInfo column name
Alter table userInfo CHANGE userSex userSexs INT;


# Modifying the type of the userInfo column name
Alter table userInfo MODIFY userSex INT;


# Deleting columns in Table userInfo
Alter table userInfo DROP userWages;


# Add four spaces before the article
Update article set content = concat ('', content );


# Query the currently used database
Select database ();
 
# TABLE Information contained in the current database
Show tables;
 
# Obtain the current time
Select now ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.