Adding ForeignKeys to a table - sql

I'm using PostgreSQL for a school project and I'm trying to add different foreign keys to my database tables but when i run for example:
ALTER TABLE PARTSUPP ADD FOREIGN KEY (PS_SUPPKEY) REFERENCES SUPPLIER(S_SUPPKEY);
on the SQL shell I receive the following error message:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
I hope that you can help me with this problem!

Your PostgreSQL server is crashing when you run your statement. There may be more information available in the Postgres logs.

Related

Microsoft Access Deadlocks on SQL server

We are experiencing some problems with SQL Deadlocks when connecting via MS Access.
Is there any way to debug this kind of error. I'm not really a SQL expert (Sorry for that).
This is the exact error I get:
[Microsoft][ODBC SQL Server Driver][SQL Server]Transaction (Proces ID 189) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. (#1205).
We have a SQL Server 2008R2 environment.
There are three things you can try:
Add a new column with the data type "timestamp" in every table. That is automatically used as a unique key, even if it's not set as a key.
Set standard values for every "bit" column. Access can't read NULL in bit values and tries to set it to false on it's own and that causes an error.
Set a primary key in every table. Make sure it is unique.
These rules apply only for tables and views which are connected to your Access DB. Reconnect the tables after you made the changes.

Merge replication error the schema script could not be propagated to the subscriber SQL Server 2008

I am with replication so after trying for 1 month I am able to initialize publisher on remote system and subscriber on my local system. When I run job at subscriber end I get an error
the schema script AccountNotic1234.sch could not be propagated to the subscriber
Somewhere I read this error happens when tables are connected using foreign keys and you missing primary table but I am synchronizing all tables. So it can not be the issue.
When I run the subscription I get error for 3 tables in order not on 1st and 2nd don't know why?
What can be the possible reasons for this?

Synchronization Bulk Insertion Exception

Any one please help me out. I am syncing sql server to client using MS Sync Framework. I am getting this exception at syncOrchestrator.Synchronize();
Failed to execute the command 'BulkInsertCommand' for table ‘xyz'; the transaction was rolled back. Ensure that the command syntax is correct.
Inner Exception is:
Violation of PRIMARY KEY constraint 'PK__#B1CF471__ECD9228532A93525'. Cannot insert duplicate key in object 'dbo.#changeTable'. The duplicate key value is (0). The data for table-valued parameter \"#changeTable\" doesn't conform to the table type of the parameter. The statement has been terminated.
There is a store procedure that using above object 'dbo.#changeTable', but I don't know what to do with that??

Upsizing Access to SQL Server

I use Access 2010 and SQL Server 2005. I am new to the process of "upsizing" which I understand is a legacy term. When I make changes to published tables, I like to localize them back into Access, alter them with the Access interface, and then "re-upsize" them to SQL Server. When I "re-uspize" an altered table Access warns me:
"A table named xxxx already exists. Do you want to overwrite it?"
I choose yes. Then Access reports an error
"Server Error 3726: Could not drop object 'xxxx' because it is
referenced by a FOREIGN KEY constraint."
I understand the importance of foreign key constraints. I have encountered this same trouble using MySQL. In MySQL I would simply set Foreign_Key_Checks = 0; before the import, then set Foreign_Key_Checks = 1; when finished.
Unfortunately in SQL Server, a table cannot be dropped while it's keys are only disabled, they must be deleted. I don't want to delete and recreate foreign keys every time I alter a table. Do I need to start altering my tables in the SQL Server environment? Is there a way to easily "Re-upsize" a table and ignore foreign Key constraints?
If you need to use Access for a front end, instead of keeping an Access DB locally and dealing with the issues of moving back and forth. Try to use Access and connect directly to a version of the sql database you can develop against directly through access. You will probably want to look into using a linked datasource in Access to SQL.
Connecting SQL Server to an Access Database

PostgreSQL - Rename database

I need to rename the database but when I do in
PGAdmin : ALTER DATABASE "databaseName" RENAME TO "databaseNameOld" it told me that it cannot.
How can I do it?
(Version 8.3 on WindowsXP)
Update
The first error message : Cannot because I was connect to it. So I selected an other database and did the queries.
I get a second error message telling me that it has come user connect. I see in the PGAdmin screen that it has many PID but they are inactive... I do not see how to kill them.
Try not quoting the database name:
ALTER DATABASE people RENAME TO customers;
Also ensure that there are no other clients connected to the database at the time. Lastly, try posting the error message it returns so we can get a bit more information.
For future reference, you should be able to:
-- disconnect from the database to be renamed
\c postgres
-- force disconnect all other clients from the database to be renamed
SELECT pg_terminate_backend( pid )
FROM pg_stat_activity
WHERE pid <> pg_backend_pid( )
AND datname = 'name of database';
-- rename the database (it should now have zero clients)
ALTER DATABASE "name of database" RENAME TO "new name of database";
Note that table pg_stat_activity column pid was named as procpid in versions prior to 9.2. So if your PostgreSQL version is lower than 9.2, use procpid instead of pid.
I just ran into this and below is what worked:
1) pgAdmin is one of the sessions. Use psql instead.
2) Stop the pgBouncer and/or scheduler services on Windows as these also create sessions
Unexist told me in comment to restart the database and it works! Restarting the database kill all existing connection and then I connect to an other database and was able to rename it with my initial query.
Thx all.
Instead of deploying a nuke (restarting the server) you should try to close those connections that bother you either by finding where are they from and shutting down the client processes or by using the pg_cancel_backend() function.
When connected via pgadmin, the default database will be postgres.
ALTER DATABASE postgres RENAME TO pgnew;
This will not work.
You need to right click on server in pgadmin and set Maintenance DB to some other DB and save. Then retry and it should work if no other connections exists.
For anyone running into this issue using DBeaver and getting an error message like this:
ERROR: database "my_stubborn_db" is being accessed by other users
Detail: There is 1 other session using the database.
Disconnect your current connection, and reconnect to the same server with a connection that doesn't target the database you are renaming.
Changing the active database is not enough.
ALTER DATABASE old_database RENAME TO new_database;
old_database means already existing database.
new_database means need to modify this name.
Example: ALTER DATABASE profile RENAME TO address;