Transact-SQL示例
时间: 2023-07-05 16:35:41 浏览: 108
transact-SQL
以下是一些 Transact-SQL 的示例:
1. 创建一个表
```
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(50),
age INT,
gender VARCHAR(10)
);
```
2. 插入数据
```
INSERT INTO students (id, name, age, gender)
VALUES (1, 'Alice', 18, 'Female'),
(2, 'Bob', 20, 'Male'),
(3, 'Charlie', 19, 'Male');
```
3. 查询数据
```
SELECT name, age
FROM students
WHERE gender = 'Male'
ORDER BY age DESC;
```
4. 更新数据
```
UPDATE students
SET age = 21
WHERE name = 'Bob';
```
5. 删除数据
```
DELETE FROM students
WHERE id = 3;
```
6. 创建一个存储过程
```
CREATE PROCEDURE get_student_info
@id INT
AS
BEGIN
SELECT name, age, gender
FROM students
WHERE id = @id;
END;
```
7. 调用存储过程
```
EXEC get_student_info @id = 1;
```
以上是一些简单的 Transact-SQL 示例,它们可以帮助你了解 T-SQL 的基本语法和用法。
阅读全文