This cookie is set by GDPR Cookie Consent plugin. The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". The cookie is used to store the user consent for the cookies in the category "Analytics". These cookies ensure basic functionalities and security features of the website, anonymously. Necessary cookies are absolutely essential for the website to function properly. on How to List Installed Packages and Version using pip tool How to Install NumPy - Just Another Sharing Site.Function in Python - Just Another Sharing Site.Anonymous on How to Solve Error Message Failed to execute goal :maven-war-plugin:2.3:war (default-war) on project app: Execution default-war of goal :maven-war-plugin:2.3:war failed: Unable to load the mojo ‘war’ in the plugin ‘:maven-war-plugin:2.3’ due to an API incompatibility: .: null when compiling and building Java Web Application in NetBeans.Angélica on How to Solve Error Message Failed to execute goal :maven-war-plugin:2.3:war (default-war) on project app: Execution default-war of goal :maven-war-plugin:2.3:war failed: Unable to load the mojo ‘war’ in the plugin ‘:maven-war-plugin:2.3’ due to an API incompatibility: .: null when compiling and building Java Web Application in NetBeans.Anonymous on How to Solve Error Message Cannot destructure property ‘identifier’ of ‘req.body’ as it is undefined in NodeJS Application.Another one is the ‘Foreign-key constraints’ information in the child table. There is a ‘Referenced by’ information in the parent table. The result of adding the foreign key constraint above is very clear. "fk_table_0" FOREIGN KEY (parent_id) REFERENCES table_0(id) ON UPDATE CASCADE ON DELETE CASCADE TABLE "table_1" CONSTRAINT "fk_table_0" FOREIGN KEY (parent_id) REFERENCES table_0(id) ON UPDATE CASCADE ON DELETE CASCADE Test=# ALTER TABLE table_0 add constraint db_id_fkey foreign key(db_id) REFERENCES table_1(db_id) ON UPDATE CASCADE ON DELETE CASCADE Ĥ. List the available tables in the connected PostgreSQL Database by typing the following command : ![]() ![]() Below is the command for connecting to PostgreSQL Database psql -Uuser testĢ. In other words, it is the task to connect to the PostgreSQL Database in this article. The execution to perform the task is done in a command line interface. First of all, connect to the PostgreSQL Database. Using the above tables previously created, the following are the steps for adding foreign key to the table in PostgreSQL Database.ġ. It is Comparing with the description of the two tables after adding the foreign key constraint.Īdding Foreign Key to the Table in PostgreSQL Database It can be a proof for further comparison with the other output. Id | integer | | not null | nextval('table_1_id_seq'::regclass) | plain | |ĭescribing both two tables above has a certain purpose. Id | integer | | not null | nextval('table_0_id_seq'::regclass) | plain | | Test=# alter table table_1 add constraint fk_table_0 foreign key(parent_id) references table_0(id) on update cascade on delete cascade Ĭolumn | Type | Collation | Nullable | Default | Storage | Stats target | Description Last but not least, try to describe both the two tables as follows : Test=# create table table_1(id serial primary key, name text, parent_id int) ĥ. Test=# create table table_0(id serial primary key, name text) The following are the process for creating those tables : The first table name is ‘table_0’ and the second one is ‘table_1’. ![]() One of the table will have a foreign key referencing to the column inside the other table. The two tables will show the relationship between them. In order to create the simulation, create two new tables. You are now connected to database "test" as user "postgres". The following is the step for connecting to the database, just by typing ‘\c’ in PostgreSQL Command Console : After successfully creating the new database, connect to the database. The following is the command or query for creating a new database named ‘test’ :ģ. Below is the command for connecting to PostgreSQL Database psql -Upostgres postgresĢ.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |