首页 > 代码库 > SQL索引及视图常用语法

SQL索引及视图常用语法

ALTER TABLE department  ADD INDEX dept_name_idx (name);
SHOW INDEX FROM department \G
ALTER TABLE department DROP INDEX dept_name_idx;
ALTER TABLE department ADD UNIQUE dept_name_index (name);
CREATE VIEW customer_vw (cust_id, fed_id, cust_type_cd, address, city, state, zipcode ) AS SELECT cust_id, CONCAT(ends in , substr(fed_id, 8, 4)) fed_id, cust_type_cd, address, city, state, postal_code FROM customer;
SELECT cust_type_cd, count(*) FROM customer_vw WHERE state = MA GROUP BY cust_type_cd ORDER BY 1;
SELECT cst.cust_id, cst.fed_id, bus.name FROM customer_vw cst INNER JOIN business bus ON cst.cust_id = bus.cust_id;
SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = bank ORDER BY 1;

 

SQL索引及视图常用语法