sql server语句大全
时间: 2023-09-27 17:05:22 浏览: 128
以下是 SQL Server 常用语句:
1. 创建数据库:
CREATE DATABASE database_name;
2. 删除数据库:
DROP DATABASE database_name;
3. 创建表:
CREATE TABLE table_name (
column1 datatype1 null/not null,
column2 datatype2 null/not null,
column3 datatype3 null/not null,
.....
);
4. 删除表:
DROP TABLE table_name;
5. 插入数据:
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
6. 更新数据:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
7. 删除数据:
DELETE FROM table_name WHERE condition;
8. 查询数据:
SELECT column1, column2, ... FROM table_name WHERE condition ORDER BY column_name ASC/DESC;
9. 连接表:
SELECT column1, column2, ... FROM table1 INNER JOIN table2 ON condition;
10. 聚合函数:
SELECT COUNT(column_name), SUM(column_name), AVG(column_name), MIN(column_name), MAX(column_name) FROM table_name;
11. 子查询:
SELECT column_name(s) FROM table_name WHERE column_name OPERATOR (SELECT column_name FROM table_name WHERE condition);
12. 分组:
SELECT column_name(s) FROM table_name GROUP BY column_name(s);
13. 过滤分组:
SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s);
14. 排序分组:
SELECT column_name(s) FROM table_name GROUP BY column_name(s) ORDER BY column_name(s) ASC/DESC;
15. 限制结果集:
SELECT column_name(s) FROM table_name LIMIT number;
以上是 SQL Server 常用语句的一部分,还有很多其他语句和用法,需要根据具体情况进行选择和使用。
阅读全文