0
点赞
收藏
分享

微信扫一扫

comp3311 - week3 辅导notes


comp3311 - week3 辅导notes_算法


如果这个表被其他列引用,那么,哪怕有一些row没被引用,也无法删除beers表里的内容。

可以用下面这种方法删除:

comp3311 - week3 辅导notes_comp3411_02

join

SELECT   s.id, s.name, avg(e.mark) as avgMark
FROM Students s
JOIN Enrolments e on (s.id = e.student)
GROUP BY s.id, s.name
-- or --
SELECT s.id, s.name, avg(e.mark) as avgMark
FROM Students s, Enrolments e
WHERE s.id = e.student
GROUP BY s.id, s.name

一个join是和where相同的。

view

更新view

comp3311 - week3 辅导notes_算法_03


满足上面的情况才能更新view:

  1. view中不能有派生属性
  2. view中没有的属性,会是null

You can insert rows into a view only if the view is modifiable and contains no derived columns. The reason for the second restriction is that an inserted row must provide values for all columns, but the database server cannot tell how to distribute an inserted value through an expression. An attempt to insert into the response view, as the previous example shows, would fail.

When a modifiable view contains no derived columns, you can insert into it as if it were a table. The database server, however, uses NULL as the value for any column that is not exposed by the view. If such a column does not allow NULL values, an error occurs, and the insert fails.

Another mechanism for inserting rows (or performing UPDATE or DELETE operations) on IBM® Informix® views, including complex views, is to create INSTEAD OF triggers, as described in the IBM Informix Guide to SQL: Syntax.

comp3311 - week3 辅导notes_sql_04


插入之后,view会重新对表格查询,获取结果到view中。

Queries on Multiple Tables

exercise

prac

调试小知识:

psql weblog -f Hosts.sql > .errs 2>&1
grep

2>&1
File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr).

Here is one way to remember this construct (although it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as “redirect stderr to a file named 1”. & indicates that what follows and precedes is a file descriptor and not a filename. So the construct becomes: 2>&1.

Consider >& as redirect merger operator.

通过grep可以找到所有带error一行的错误。

psql的字符串处理函数更多,功能更强

substr

sqlite3 和psql的区别

view上的区别

prac5


举报

相关推荐

0 条评论