sqlserver数据库代码
时间: 2024-09-25 14:04:55 浏览: 28
SQL Server是一个强大的关系型数据库管理系统,其代码通常包括查询(SQL)语句、存储过程、触发器等。下面是一些基本示例:
1. **连接到数据库**:
```sql
USE [your_database_name]; -- 更换为你的数据库名
GO
```
2. **创建表**:
```sql
CREATE TABLE Employees (
ID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Salary DECIMAL(10,2)
);
```
3. **插入数据**:
```sql
INSERT INTO Employees (ID, FirstName, LastName, Salary) VALUES (1, 'John', 'Doe', 50000);
```
4. **查询数据**:
```sql
SELECT * FROM Employees; -- 查询所有员工信息
SELECT * FROM Employees WHERE Salary > 60000; -- 搜索薪水大于60000的员工
```
5. **更新数据**:
```sql
UPDATE Employees SET Salary = 55000 WHERE ID = 1;
```
6. **删除数据**:
```sql
DELETE FROM Employees WHERE ID = 1;
```
7. **创建存储过程**:
```sql
CREATE PROCEDURE GetEmployeeDetails @id INT AS
BEGIN
SELECT * FROM Employees WHERE ID = @id;
END;
```
阅读全文