SQL tips

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.5 kB
5
Indexable
\q 					-> exit
\l			 		-> list the databases
\d					-> describe 
\d <db_name>			-> describe the specified db table
\c <db_name> 			-> connect to desired database
\i [file name]			-> execute commands from file


DROP TABLE <table_naem>;	-> terminate releations of <table_naem>


===========================================================================
===========================================================================


Postgre DataTypes : https://www.postgresql.org/docs/current/datatype.html


===========================================================================
===========================================================================


CREATE TABLE <table_name> (
	column name + data type + constraints if any
)


Exsample :

CREATE TABLE person (
	id int NOT NULL PRIMARY KEY,
	first_name VARCHAR(50) NOT NULL,
	last_name VARCHAR(50) NOT NULL,
	gender VARCHAR(6) NOT NULL,
	date_of_birth DATE NOT NULL,
	email VARCHAR(150),
)


===========================================================================
===========================================================================


INSERT INTO <table_name> (
	first_name,
	last_name,
	gender,
	date_of_birth)

VALUES ('Anne', 'Smith', 'FEMALE', DATE '1988-01-09')


P.S : YOU SHOULD SEE "INSERT 0 1".

===========================================================================
===========================================================================