数据库sql语句举例
时间: 2024-09-14 12:04:24 浏览: 42
SQL(Structured Query Language)是用于数据库管理和数据操作的标准语言。它包括一系列用于创建、查询、更新和管理数据库的命令。以下是一些基础的SQL语句示例:
1. 创建表(Create Table):
```sql
CREATE TABLE Employees (
ID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
BirthDate DATE,
HireDate DATE
);
```
2. 插入数据(Insert Into):
```sql
INSERT INTO Employees (ID, FirstName, LastName, BirthDate, HireDate)
VALUES (1, '张三', '李四', '1980-01-01', '2000-01-01');
```
3. 查询数据(Select):
```sql
SELECT FirstName, LastName FROM Employees WHERE BirthDate > '1980-01-01';
```
4. 更新数据(Update):
```sql
UPDATE Employees
SET LastName = '王五'
WHERE ID = 1;
```
5. 删除数据(Delete):
```sql
DELETE FROM Employees WHERE ID = 1;
```
6. 删除表(Drop Table):
```sql
DROP TABLE Employees;
```
7. 创建视图(Create View):
```sql
CREATE VIEW EmployeeDetails AS
SELECT ID, FirstName, LastName, BirthDate, HireDate
FROM Employees;
```
8. 连接查询(Join):
```sql
SELECT Employees.FirstName, Employees.LastName, Departments.DepartmentName
FROM Employees
JOIN Departments ON Employees.DepartmentID = Departments.ID;
```
阅读全文