Unable to view foreign keys in SQL - azure-sql-database

I am having issues with importing data into SQL using HeidiSQL. I have a really basic table that looks like so:
It has an Index on it that looks like so:
For some reason in HeidiSQL I cannot look at the Foreign Key tab:
But then I have no issue looking/creating these in SSMS:
HeidiSQL seems to get confused and will not let me look at the Foreign Key tab however SSMS has no such issue.

Looks like HeidiSQL doesn't support a few aspects of foreign keys when using Azure SQL; this guy was complaining about it two years ago: https://www.heidisql.com/forum.php?t=19139
Note the exact same error message as shown in your HS screenshot..
Kinda disappointing that it's been an issue for so long!

Related

Write back to Oracle from PowerApps

I am trying write back to Oracle table from PowerApps. But I'm getting the following error:
"The Data source is read-only, so the function Patch can't write to it"
I have access to this Oracle table and table data is also visible in my PowerApp but I cannot insert in DB from my PowerApp.
Primary key is perfectly fine, defined well with all constraints. I can insert by using SQL query in the same table but when I do same with PowerApps I get error.
Here is my Patch function.
Patch('[PLAN].[V_PLAN_L_TYP]',Defaults('[PLAN].[V_PLAN_L_TYP]') , {TYP_ID: TYP_ID_TextInput.Text, TYP_DESC: TYP_DESC_TextInput.Text,
KANAL_AKT: KANAL_AKT_TextInput.Text } );
Is it possible to write back to Oracle table or not?
This naming convention V_PLAN_L_TYP sounds to me like a view but not a table. Please verify it.
This is why that matters - Currently Oracle connector documentation says:
Support Oracle view as read-only table

Auto-increment my primary key SQL Server 2012

I'm using SQL Server 2012, I want to add an auto-increment to my primary key I don't know the exact syntax so i tried this but it obviously won't work !
Help please !!!
ALTER TABLE dbo.Equipe alter numero_equipe add IDENTITY(9999,1)
The way to solve syntax problems is not to shove characters around until it happens to work, but to read the (excellent) online docs. They specify syntax and give examples. Searching also helps to answer trivial questions.
You can perform the operation without touching table data using SWITCH: http://blogs.msdn.com/b/dfurman/archive/2010/04/20/adding-the-identity-property-to-a-column-of-an-existing-table.aspx
A connect item for a feature request exists: https://connect.microsoft.com/SQLServer/feedback/details/800127/allow-for-changes-to-the-identity-property-with-simple-syntax-and-metadata-operation-like-performance (please vote).

play20 ebean generated sql throws syntax error on postgresql

I'm trying to get work my play20 application with postgresql so I can use and later deploy to Heroku. I followed this answer.
Basically, I made connection to database (so connection from local application to Heroku postgresql database worked), but I was not able to initialise database with generated 1.sql evolution. But generated sql was not working because of postgresql is using schema (it should work without schema anyway, but apparently I'm doing something wrong or database is doing something wrong).
create table user (
id bigint not null,
email varchar(255),
gender varchar(1),
constraint pk_user primary key (id));
resulted in
ERROR: syntax error at or near "user"
Position: 14 [ERROR:0, SQLSTATE:42601]
I fixed that with adding schema to table name
create table public.user(
...
);
Ok, everything worked until I tried to read or write to database. I got again sql syntax exception and can't work with database. Seems like sql queries are somehow wrong.
Any suggestions where could be problem?
That's very common mistake while developing application with other database than in production, but fortunately there is also common solution. You can still use User model, however you have to make sure that creates database table with changed name:
#Entity
#Table(name = "users")
public class User extends Model {
...
}
In most cases in your controllers and models name-switch will be transparent for you. Only place where you have to remember the switch are RawSql queries.
BTW, that's good idea to install locally the same database for developing cause there's a lot of differences between most popular databases, like other reserved keywords, other allowed types, even other auto incrementing methods for id, so finding and fixing proper values is just easier on localhost.
Well, due to my little knowledge about postgresql, I was struggling with this all day. Here's simple solution. Don't use table called "user" on postgreqsl. This table is already used.
But why my evolution sql query worked for initialisation of database? Well if I explicitly specify in which schema I want to create table "user", that basically works.
But if schema is not specified, is used current schema. From documentation:
If a schema name is given (for example, CREATE TABLE myschema.mytable ...) then the table is created in the specified schema. Otherwise it is created in the current schema
So that explains it. But for my project, using "user" model was perfectly reasonable and for H2 file based databased it was working, so I assumed that problem was somewhere else...

Getting around cyclical foreign key errors when trying to generate insert data scripts in SQL 2008

I am trying to generate some insert scripts using the SQL Server 2008 Script Wizard. Upon generating the scripts, I get the following error:
"The selected database contains foreign keys that create a cycle. Publishing data only is not supported for databases with cyclical foreign key relationships."
I've attempted to disable and remove all constraints in the database. The error is still occurring. Is there any way to get around this? Possibly make SQL ignore the constraints while generating the scripts.
On the Wizard page where you choose the radio button to select All Database Objects or Specific Objects, make sure to select All Database Objects. For some reason the tool needs something in there to generate even if you just want the table insert script.
Once I changed that radio button to All Database Objects, and selected the Advanced option to generate Type of script = Data Only, it worked all the way through.
I had the same problem as the OP. Then I tried again, this time in the advanced options, for the "types of data to script" option, I selected "schema and data" rather than data only. Then it worked for me without complaining about cyclical keys.
I was having the same issue, and I discovered today that you can use SQL Server Management Studio 2012 against a 2008 R2 DB and you won't get the error:
Sql Server Scripting Data Only: Workaround for CyclicalForeignKeyException?
Saving to file vs. to a new Query editor window seems to make it work for me on Management Studio 2008 :\
First off IMHO HLGEM's response is a bit cavalier--there are valid reasons at times to have cyclic references.
That said I think the script generator is hyper-sensitive. It seems to think just about any PK/FK pair is "cyclic" and I ended up having to use a copy of my database from which I'd stripped all keys to get the export to get beyond the "cyclical" error. A script like the following can help you drop keys globally but of course be careful!
SELECT
'ALTER TABLE ' + object_name(parent_obj) + ' DROP CONSTRAINT ' + [name]
AS Script
from sysobjects where xtype IN ('F')
[I didn't write this. See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=46682]
Further the tool is pretty useless in terms of feedback since its report doesn't provide enough detail to narrow down where the supposed cyclical references exist.
Finally I found the tool to be pretty flaky in that I get random timeouts. One other observation that I haven't researched extensively is I think the tool may require you to start from scratch after the cyclical error to clear it's cache since I see different behavior when I use Previous button vs. starting afresh.
You can export the data by setting the script option - "Script Check Constraints" to False
Sorry this will not work :(
You will have to determine which table is causing the issue.
I was getting the same error because I didn't had a table selected in the object list (one big table I wanted to create in another script). Selecting all of the tables solved the problem.
PD: Maybe a little bit late, but searching CyclicalForeignKeyException gets first in Google.

Rename foreign key system name in SQL Server Management Studio is failing

The method or operation is not
permitted.
I assume this is a permission's issue, but I can't figure out where I would change it. It is strange because I can rename an index with no issue.
EDIT:
If you're looking at a table, and you see "Columns, Keys, Constraints, etc.", this is under Keys, and it is the system name that I presume SQL is using to identify the foreign key name I gave the column.
What is the exact error you are getting?
Also, generate a script for your change and paste that script into a query window and try it there. See what the error is. Note that SSMS GUI stuff is NOT the best place to do stuff like this.