侧边栏

SQL 笔记

SQL 语句

drop table 删除表

drop table if exists table_name;

如果表名存在则删除
执行该语句需要有足够的数据库权限。如果没有相应的权限,数据库会拒绝执行该操作并返回错误信息。

CREATE TABLE 创建表

CREATE TABLE table_name (
    column1 datatype [constraint],
    column2 datatype [constraint],
    ...
    [table_constraint]
    // 例如 `gender` varchar(14) NOT NULL,
};

SELECT 查询所有列

select list_name from table_name;

对查询的所有列去重

distinct

select distinct list_name from table_name;

group by 利用分组,实现去重

select list_name from table_name group by list_name;

Limit 限制输出

select list_name from table_name limit Number;

As 将查询后的列重新命名

select last_list_name as new_list_name from table_name;

where

查找所有列中字段为S的

select list_name from table_name where list_name = S;
posted @ 2025-02-20 22:13  Z-wzy  阅读(18)  评论(0)    收藏  举报