how to create a postgresql table? how do you use alter table and drop table? and what are the differences between Primary key and Foreign key?

Asked

Viewed 32 times

3

People help me with postgresql studies.How do you create a postgresql table? how do you use the alter table and drop table? and what differences of key Primary and key Foreign ?

  • The excellent Postgresql manual will be helpful: https://www.postgresql.org/docs/current/index.html

1 answer

1

Create table:

CREATE TABLE tabela (
    id INT NOT NULL,
    nome VARCHAR(15),
    data DATE,
    PRIMARY KEY(id)
);

Delete table:

DROP TABLE tabela;

Change table (here it is a little abstract, would have to specify more):

ALTER TABLE tabela ACAO_QUE_VOCE_QUER_EXECUTAR;

Primary key: what defines the current element. Example: the primary key of your documents to the state is your CPF, while that of a company is the CNPJ.

Foreign key: used to define an external element. Example: the cab of the XXXX-YYY plate belongs to the citizen of CPF 123.456.789-01.

Tip: When asking a question in the community, try to be a little more specific, and you’ll get more accurate answers ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.