摘要: 创建一个函数 创建一个trigger, 将表和函数绑定 ALTER TRIGGER trigger_name ON table_name RENAME TO new_name; ALTER TRIGGER last_name_changes ON employees RENAME TO log_last_name_changes; ALTER TABLE table_name DISA... 阅读全文
posted @ 2016-04-24 11:47 songlihong 阅读(157) 评论(0) 推荐(0) 编辑
摘要: CREATE OR REPLACE view_name AS query DROP VIEW [ IF EXISTS ] view_name; 一个复杂的 query: SELECT cu.customer_id AS id, (((cu.first_name)::text || ' '::text) || ... 阅读全文
posted @ 2016-04-24 10:32 songlihong 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 增:insert INSERT INTO products (product_no, name, price) VALUES (1, 'Cheese', 9.99), (2, 'Bread', 1.99), (3, 'Milk', 2.99); 可以一次插入多行数据。 INSERT INTO products (product_no, name, price) VALUES... 阅读全文
posted @ 2016-04-18 17:23 songlihong 阅读(278) 评论(0) 推荐(0) 编辑
摘要: CREATE TABLE products ( product_no integer, name text, price numeric CONSTRAINT positive_price CHECK (price > 0) ); CHECK 返回bool 值。 外键参照完整性、引用完整性 A foreign key constraint specifies th... 阅读全文
posted @ 2016-04-16 09:39 songlihong 阅读(393) 评论(0) 推荐(0) 编辑
摘要: 函数调用, 这个简单 CREATE FUNCTION concat_lower_or_upper(a text, b text, uppercase boolean DEFAULT false) RETURNS text AS $$ SELECT CASE WHEN $3 THEN UPPER($1 || ' ' || $2) ELSE LOWER($1 || '... 阅读全文
posted @ 2016-04-08 16:24 songlihong 阅读(139) 评论(0) 推荐(0) 编辑
摘要: A value expression is one of the following: A constant or literal value A column reference A positional parameter reference, in the body of a function definition or prepared statement A subscripted ex... 阅读全文
posted @ 2016-04-08 15:59 songlihong 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 4.1. Lexical Structure (SQL命令的结构or组成) A token can be akey word, anidentifier, aquoted identifier, aliteral(or constant), or a special character symbol. SQL语句的基本组成 关键字:SELECT, INSERT, UP... 阅读全文
posted @ 2016-04-08 15:31 songlihong 阅读(239) 评论(0) 推荐(0) 编辑