Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgres parent and child tables

DROP TABLE IF EXISTS customers;
DROP TABLE IF EXISTS contacts;

CREATE TABLE customers(
   customer_id INT GENERATED ALWAYS AS IDENTITY,
   customer_name VARCHAR(255) NOT NULL,
   PRIMARY KEY(customer_id)
);

CREATE TABLE contacts(
   contact_id INT GENERATED ALWAYS AS IDENTITY,
   customer_id INT,
   contact_name VARCHAR(255) NOT NULL,
   phone VARCHAR(15),
   email VARCHAR(100),
   PRIMARY KEY(contact_id),
   CONSTRAINT fk_customer
      FOREIGN KEY(customer_id) 
	  REFERENCES customers(customer_id)
);
Code language: SQL (Structured Query Language) (sql)
Comment

PREVIOUS NEXT
Code Example
Sql :: postgres extract date from timestamp 
Sql :: insert query mysql workbench 
Sql :: how to get specific salary in sql 
Sql :: how to casting data types in postgresql 
Sql :: mysql best tutorial for beginners 
Sql :: how to join three tables in sql using joins 
Sql :: mysql sql select one day before 
Sql :: group by por mes sql mysql 
Sql :: postgresql create table as select 
Sql :: sql unique select 
Sql :: case insensitive sql 
Sql :: mysql concat and use as where column 
Sql :: count in sql 
Sql :: SQL SELECT TOP Equivalent in MySQL 
Sql :: mysql alter table add column 
Sql :: r write csv without index 
Sql :: mariadb create view 
Sql :: mariadb create index if not exists 
Sql :: SQL Find text in SPs 
Sql :: how to use query in nosql 
Sql :: if else sql 
Sql :: select indexes postgres 
Sql :: else if sql 
Sql :: sql create cluster index 
Sql :: carbon mysql d m y to y-m-d 
Sql :: azure check access to sql database 
Sql :: delete and drop in sql 
Sql :: oracle sql all days except weekends 
Sql :: select all from table left join 
Sql :: create directory in sql server 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =