Otherwise it is created in the current schema. ) then the table is created in the specified schema. If a schema name is given (for example, CREATE TABLE myschema.mytable. The table will be owned by the user issuing the command. This example would create a new table called current_inventory based on column definitions from both the products and categories tables.Īgain, only the records that met the conditions of the SELECT statement would be populated into the new current_inventory table. CREATE TABLE will create a new, initially empty table in the current database. ON products.category_id = categories.category_id The following SQL statement will create a table named members in your PostgreSQL database: CREATE TABLE cars (. SELECT products.product_id, products.product_name, categories.category_name Next, let's look at a CREATE TABLE AS example that shows how to create a table by copying selected columns from multiple tables.įor example: CREATE TABLE current_inventory AS In other words, all records from the products table with a quantity greater than 0 would be inserted into the current_inventory table when it was created. If there were records in the products table, then the new current_inventory table would be populated with the records returned by the SELECT statement. Expand Schemas, public, Tables, right click on the Tables and click on Create, Table. This example would create a new table called current_inventory that included all columns from the products table. Let's look at a PostgreSQL CREATE TABLE AS example that shows how to create a table by copying all columns from another table.
0 Comments
Leave a Reply. |