why the output error, I do not understand - sqlyog

create table qbey (
idqbey int primary key auto_increment,
bey int,
users int,
foreign key (users) references persons(idusers) on delete cascade on update cascade,
foreign key (bey) references bey(idbey) on delete cascade on update cascade,
);
Program Error:
error code: 1005 can't create table '.\soft_tj\qbey.frm' (errno:150)

The documentation explains this error, though it's not too easy to find: http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
If you re-create a table that was dropped, it must have a definition
that conforms to the foreign key constraints referencing it. It must
have the right column names and types, and it must have indexes on the
referenced keys, as stated earlier. If these are not satisfied, MySQL
returns error number 1005 and refers to error 150 in the error
message.

Related

Cassandra, Delete if a set contains value

I'm a beginner in Cassandra and I have a table like this:
CREATE TABLE Books(
Title text PRIMARY KEY,
Authors set<text>,
Family set <text>,
Publisher text,
Price decimal
);
(the other options are missing because it's only an example)
now I would like to execute this query:
DELETE Price FROM Books WHERE Authors CONTAINS 'J.K. Rowling' IF EXISTS;
But it doesn't work. I searched on Google but found nothing.
Hope somebody can help me and sorry if my english is not very good.
but it doesn't work.
That doesn't really give us enough information to help you. Usually, you'll want to provide an error message. I built your table locally, inserted data, and tried your approach. This is the error that I see:
InvalidRequest: Error from server: code=2200 [Invalid query]
message="Some partition key parts are missing: title"
DELETE requires that the appropriate PRIMARY KEY components be specified in the WHERE clause. In your case, Authors is not part of the PRIMARY KEY definition. Given the error message returned (and the table definition) specifying title is the only way to delete rows from this table.
aploetz#cqlsh:stackoverflow> DELETE FROM Books
WHERE title = 'Harry Potter and the Chamber of Secrets'
IF EXISTS;
[applied]
-----------
True
Can I do a query like this? UPDATE Books SET Family = Family + {'Fantasy'} WHERE Authors CONTAINS 'J.K. Rowling';
No. This fails for the same reason. Writes in Cassandra (INSERTs, UPDATEs, DELETEs are all writes) require the primary key (specifically, the partition key) in the WHERE clause. Without that, Cassandra can't figure out which node holds the data, and it needs that to perform the write.

Why referential integrity constraints are not working in my code? How do I fix this?

I have made dno as my primary key in departmentdum1 table ,and the dno in sigdum14 is referencing to departmentdum1 table dno attribute .I should get the error when I execute this code because I'm trying to put dno value as 5 in sigdum14 table which should show error but it is not showing
from tkinter import *
import sqlite3
conn = sqlite3.connect('Form.db')
print("connected")
conn.execute('create table departmentdum1 (d_name varchar(20),dno int
primary key)')
print("created");
conn.execute('insert into departmentdum1 values("computer science",1)')
print("execute");
conn.execute('insert into departmentdum1 values("Information
science",2)')
print("execute");
conn.execute('create table sigdum14 ( y_name varchar(20),dno integer,
foreign key(dno) REFERENCES departmentdum1(dno))') ;
print("created");
conn.execute('insert into sigdum14 values("kim",5)')
print("execute");
print("desc done");
conn.commit();
connected
created
execute
execute
created
execute
desc done
The output is wrong!!
sqlite doesn't enforce foreign key constraints by default. However, you can change this behavior by adding this line:
conn.execute("PRAGMA foreign_keys = 1")
just after opening your connection.
For more details, see chapter 2 of the doc:
In order to use foreign key constraints in SQLite, the library must be compiled with neither SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined. [...]
Assuming the library is compiled with foreign key constraints enabled, it must still be enabled by the application at runtime, using the PRAGMA foreign_keys command.

How does Cassandra CQL add constraints?

I can't seem to create a table like this, whose constraints portion is throwing error.
CREATE TABLE admins (
id UUID PRIMARY KEY,
username text,
password text,
name text,
access_level text,
CONSTRAINT access_types CHECK(access_level) in ('true', 'false')
);
SyntaxException: line 7:28 mismatched input 'CHECK' expecting ')' (... access_level text, access_types CONSTRAINT [CHECK]...)
How do I add constraints? I can't seem to find a way to add constraints with cql, which doesn't seem to have documentation for it. If this is not supported, why?
Cassandra doesn't have this kind of constraint. Usually, it's up to your app care about it.

Postgres syntax error for reference

I am trying to create a table with the following query using the pg npm module (v7):
CREATE TABLE subscriptions(
id SERIAL PRIMARY KEY,
stripe_id VARCHAR(40) UNIQUE NOT NULL,
user INTEGER REFERENCES users,
plan VARCHAR(40) NOT NULL,
active BOOLEAN NOT NULL,
start DATE NOT NULL,
end DATE DEFAULT NULL
);
This seems to match the docs but it is throwing an error:
error: syntax error at or near "user"
The users table has a serial primary key for id, anyone know why this isn't working?
Edit: here's the docs for reference - https://www.postgresql.org/docs/9.4/static/ddl-constraints.html#DDL-CONSTRAINTS-FK
I'm using postgresql version 9.4.
user is a reserved keyword in postgresql. You may use any other column name in its place
Refer the postgresql documentation for the complete list of keywords - Key Words List
According to it, end is also reserved. So the last line of your code will generate an error

Non frozen collections and user defined types on Cassandra 2.1.8

I'm trying to run the following example from here
CREATE TYPE address (
street text,
city text,
zip int
);
CREATE TABLE user_profiles (
login text PRIMARY KEY,
first_name text,
last_name text,
email text,
addresses map<text, address>
);
However, when I try to create the user_profiles table, I get the following error:
InvalidRequest: code=2200 [Invalid query] message="Non-frozen collections are not
allowed inside collections: map<text, address>
Any thoughts on why this could be happening?
I am running 2.1.8 and I get the same error message. To fix this, you need the frozen keyword:
CREATE TABLE user_profiles (
login text PRIMARY KEY,
first_name text,
last_name text,
email text,
addresses map<text, frozen <address>>
);
Frozen is necessary for UDTs (for now) as it serializes them into a single value. A similar, better example for you to follow might be the one in the User Defined Type documentation. Give that a try.
I was getting this message when I mistakenly used "string" instead of "text" in a cassandra map, like:
mymap map<bigint, string>
I followed this stackoverflow thread from google and I thought this information could save someone a few minutes of their time.
Non-frozen UDTs are not yet supported. The reason for asking the user to explicitly specify this keyword for each UDT is to be able to introduce mutable UDTs in 3.x without breaking existing code.

Resources