Remote web server - CHAPTER 28 FROM DATABASES TO DATATYPES List

CHAPTER 28 FROM DATABASES TO DATATYPES List of relations Schema | Name | Type | Owner ————-+———-+——-+——mynewschema | customer | table | rob public | customer | table | rob (2 rows) This example shows two tables named customer located in the company database. The first table is in the schema we created called mynewschema, and the second table is in the default schema called public. Remember that the public schema is automatically created for you and that, by default, all tables will be created within that schema unless you designate otherwise. Working with Tables This section demonstrates how to create, list, review, delete, and alter tables in PostgreSQL. Creating a Table A table is created using the CREATE TABLE statement. A vast number of options and clauses specific to this statement are available, but it seems a bit impractical to introduce them all in what is an otherwise informal introduction. Instead, we ll introduce various features of this statement as they become relevant in future sections. The purpose of this section is to demonstrate general usage. As an example, let s create an employee table for the company database: company=# CREATE TABLE employee ( company(# empid SERIAL UNIQUE NOT NULL, company(# firstname VARCHAR(40) NOT NULL, company(# lastname VARCHAR(40) NOT NULL, company(# email VARCHAR(80) NOT NULL, company(# phone VARCHAR(25) NOT NULL, company(# PRIMARY KEY(empid) company(# ); NOTICE: CREATE TABLE will create implicit sequence “employee_empid_seq” for serial column “employee.empid” NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index “employee_pkey” for table “employee” CREATE TABLE You can always go back and alter a table structure after it has been created. Later in the chapter, the section Altering a Table Structure demonstrates how this is accomplished via the ALTER TABLE statement. You will notice that creating this table produces several notices about things like sequences and indexes. Don t worry about these for now the meaning of SERIAL, UNIQUE, NOTNULL, and so on will be described later in the chapter.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Leave a Reply