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 ();