This is the command to create a new database,
CREATE DATABASE mydb;
This is the command to create a new table,
CREATE TABLE IF NOT EXISTS mytable ( int a PRIMARY KEY );
But this does not add the mytable
inside the mydb
. How to add the table inside the database mydb
?
Codename KCodename K
asked Jun 19, 2018 at 6:04
-
1what operating system are you using?Evan Carroll– Evan Carroll2018年06月19日 06:10:10 +00:00Commented Jun 19, 2018 at 6:10
-
Windows 10 (64bit)Codename K– Codename K2018年06月19日 06:18:51 +00:00Commented Jun 19, 2018 at 6:18
1 Answer 1
But this does not add the mytable inside the mydb. How to add the table inside the database mydb?
You have to connect to the database mydb
,
psql -d mydb
Then run the command
answered Jun 19, 2018 at 6:09
-
1Where? Did you put a space between the dash and the d?
-d
?Evan Carroll– Evan Carroll2018年06月19日 06:30:06 +00:00Commented Jun 19, 2018 at 6:30 -
1so where is that error coming from, I have no idea. Does your table name or column name have a
-
in it?Evan Carroll– Evan Carroll2018年06月19日 06:32:18 +00:00Commented Jun 19, 2018 at 6:32 -
1@CodenameK do you have anything in your
psqlrc
?Evan Carroll– Evan Carroll2018年06月19日 06:38:06 +00:00Commented Jun 19, 2018 at 6:38 -
2@CodenameK: you need to run that on the windows command line. That is not a SQL statement. You simply start
psql
and connect to the new database. If you already startedpsql
you need to use\connect
to switch to a different databaseuser1822– user18222018年06月19日 07:12:05 +00:00Commented Jun 19, 2018 at 7:12 -
1If the database is dropped, you can't connect to it to see if the table exists. And no one can be connected to the database that you're dropping. You have to drop it while connecting to a different database.Evan Carroll– Evan Carroll2018年06月19日 19:03:26 +00:00Commented Jun 19, 2018 at 19:03
lang-sql