SELECT*FROM student where sid=? or sname=?
时间: 2024-02-16 18:01:32 浏览: 37
这是一个 SQL 查询语句,用于从名为 student 的表中查询满足条件的记录。其中 "?" 和 "?" 分别代表两个不同的占位符,用于传入查询条件。具体而言,这个查询语句会返回所有满足 sid 等于指定值或者 sname 等于指定字符串的记录。请注意,这个查询语句是不完整的,需要在程序中使用具体的参数值来替换占位符,否则无法执行成功。
相关问题
D:\>sqlite3 mydb.db create table t_student(sid INTEGER primary key,sname varchar(20)); insert into t_student(sid,sname)values(1,'coolsy'); select * from t_student; select sid,sname from t_student; insert into t_student(sid,sname)values(2,'Tom'); insert into t_student(sid,sname)values(3,'Rose'); insert into t_student(sid,sname)values(4,'Eva'); select * from t_student; update t_student set sname='Kuka' where sid=1; select * from t_student; delete from t_student where sid=4; select * from t_student; select * from t_student order by sid desc; select * from t_student order by sid asc; select sname from t_student where sid between 1 and 2;
这是一段SQLite命令行操作数据库的代码。它创建了一个名为"mydb.db"的数据库,其中有一个名为"t_student"的表格,表格有两列,分别是"sid"和"sname"。接着向表格中插入了一条记录,然后通过"select"语句查询表格中所有记录,再查询指定列的记录。接下来又插入了三条记录,并查询整个表格,更新了id为1的记录中"sname"列的值,再查询整个表格,删除了id为4的记录,再查询整个表格。最后进行了一些排序和条件查询。
写出测试CREATE TRIGGER tr_stu_dept ON student AFTER INSERT, UPDATE AS IF EXISTS (SELECT * FROM INSERTED WHERE sdept = '计算机系' OR sdept !='信息管理系' OR sdept !='数学系' OR sdept !='通信工程系') ROLLBACK 的执行情况的代码
假设我们已经有了一个名为 `student` 的表,其中包含sid`, `sname`, `sdept` 个字段。
接下来,我们可以使用以下代码创建一个名为 `tr_stu_dept` 的触发器:
```
CREATE TRIGGER_stu_dept
ON student
AFTER INSERT, UPDATE
AS
BEGIN
IF EXISTS (SELECT * FROM INSERTED WHERE sdept = '计算机系' OR sdept != '信息管理系' OR sdept != '数学系' OR sdept != '通信工程系')
ROLLBACK;
END;
```
该触发器将在每次向 `student` 表中插入或更新记录时执行。当插入或更新的记录的 `sdept` 字段等于 `'计算机系'` 或不等于 `'信息管理系'`, `'数学系'`, `'通信工程系'` 中的任何一个值时,该触发器会阻止该操作并回滚。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)