Postgresql Altering Table

Is it possible to alter a table to add a new column and make that column a foreign key to another table in a single command in Postgresql? "alter table x add column y id references z(id)" doesn't seem to work as I had hoped.

Answers


You can do it. What is "y id"? May be

alter table x add column y int references z(id)

BEGIN
ALTER TABLE ... ADD COLUMN ...
ALTER TABLE ... ADD CONSTRAINT ...
COMMIT

You can't convince me it's not a single command :).


Need Your Help

SQLException Obtaining more information

sql-server vb.net ado.net sqlexception

Currently working with converting SQLException error messages into messages that are more useful for the end user. My largest issue has been finding the information I'm looking for.

Limitations of C# to native interop

c# .net interop pinvoke native

I know that C# allows interoperability with native code using PInvoke (An Overview of Managed/Unmanaged Code Interoperability)