create database in pg admin code example

Example 1: create postgres database

sudo -u postgres psql
postgres=# create database mydb;
postgres=# create user myuser with encrypted password 'mypass';
postgres=# grant all privileges on database mydb to myuser;

Example 2: create database mysql

CREATE DATABASE `mydb`;

CREATE TABLE `my_table`
(
	my_table_id INT AUTO_INCREMENT,
    my_table_name VARCHAR(30) NOT NULL,
    my_foreign_key INT NOT NULL,
    my_tb_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  	my_tb_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, ,
    # Any other properties here
    PRIMARY KEY(my_table_id),
    CONSTRAINT fk_name_of_parent_table
    FOREIGN KEY(my_foreign_key) REFERENCES parent_table(parent_table_column)
);

SHOW DATABASES;

Example 3: create database in phpmyadmin

//To create database you can execute below query
>create database db_name

Tags:

Misc Example