首页 > 数据库 > 数据库开发技术 > PostgreSQL 复制表的 5 种方式
CREATE TABLE emp2
AS
SELECT * FROM employee;
CREATE TABLE emp2
AS
SELECT * FROM employee
WITH NO DATA;
CREATE TABLE emp2
AS
SELECT * FROM employee
WHERE FALSE;
CREATE TABLE emp3
(LIKE employee);
CREATE TABLE emp4
AS
TABLE employee;
CREATE TABLE emp4
AS
TABLE employee
WITH NO DATA;
SELECT * INTO emp5 FROM employee;
CREATE TABLE emp5 (
notes text NOT NULL
)
INHERITS ( employee );
\d emp5
Table "public.emp5"
Column | Type | Collation | Nullable | Default
-----------+------------------------+-----------+----------+---------
emp_id | integer | | not null |
emp_name | character varying(50) | | not null |
sex | character varying(10) | | not null |
dept_id | integer | | not null |
manager | integer | | |
hire_date | date | | not null |
job_id | integer | | not null |
salary | numeric(8,2) | | not null |
bonus | numeric(8,2) | | |
email | character varying(100) | | not null |
notes | text | | not null |
Check constraints:
"ck_emp_salary" CHECK (salary > 0::numeric)
"ck_emp_sex" CHECK (sex::text = ANY (ARRAY['男'::character varying, '女'::character varying]::text[]))
Inherits: employee
原文作者:SQL编程思想;如有侵权,请联系管理员删除。