CREATE TABLE emp(id INT PRIMARY KEY,NAME VARCHAR(11),dep_id INT ,salary INT); CREATE TABLE dept(id INT PRIMARY KEY,NAME VARCHAR(11),parentid INT); 获取各部门人数信息: SELECT e.dep_id,d.name,COUNT(e.dep_id) FROM emp e,dept d WHERE e.dep_id=d.id GROUP BY e.dep_
这个例子演示了如何在shell脚本中执行多个sql来操作数据库表. #! /bin/sh USER_HOME=/home/`whoami` . /etc/profile if [ -f ${USER_HOME}/.bash_profile ]; then . ${USER_HOME}/.bash_profile fi mysql -h -ujifei30 -pNapnUszJD -Dtpssprod <<EOF select table_name from information_schema