MYSQL增删改查简单示例代码

发布时间:2024年01月15日

1.建表

CREATE TABLE students (  
    id INT AUTO_INCREMENT PRIMARY KEY,  
    name VARCHAR(50),  
    age INT  
);

结构解释:

CREATE TABLE [表名] (  
    [列名] [字段类型] [AUTO_INCREMENT PRIMARY KEY  自增,主键属性],  
    [列名] [字段类型],  
    [列名] [字段类型]  
);

2.查询

SELECT * FROM students;

结构解释:

SELECT [列名] FROM [表名];

3.更新

UPDATE students SET age = 20 WHERE name = 'John';

结构解释:

UPDATE [表名] SET [列名] = [新的值] WHERE [条件];

4.删除

DELETE FROM students WHERE name = 'John';

结构解释:

DELETE FROM [表名] WHERE [条件语句];

5.插入

INSERT INTO students (name, age) VALUES ('Alice', 18);

结构解释:

INSERT INTO [表名] [列名](name, age) VALUES [值]('Alice', 18);

文章来源:https://blog.csdn.net/Corrupt_jm/article/details/135587858
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。