Created
January 23, 2022 04:57
-
-
Save AshishPandagre/5faea32227d9ed4d2ef521b5c50c5788 to your computer and use it in GitHub Desktop.
basic psql commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- \l gives the details of databases in psql. | |
// create a database | |
CREATE DATABASE test; | |
//close the prompt and start again. | |
// enter db name to be test | |
// to create a table | |
CREATE TABLE person ( | |
id BIGSERIAL NOT NULL PRIMARY KEY, | |
name VARCHAR(100) NOT NULL, | |
country VARCHAR(100) NOT NULL ); | |
-- \d and \dt gives tables info on current db. | |
// to insert some data in the table. | |
INSERT INTO person(name, country) VALUES ('ashish', 'India'); | |
INSERT INTO person(name, country) VALUES ('ash', 'USA'); | |
// get data | |
SELECT * FROM person; | |
// update a row | |
UPDATE person SET name = 'anthony' WHERE id=3; | |
// delete a row | |
DELETE FROM person where id=2; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment