I have a somewhat strange question to ask: can I somehow hide a specific index from a specific user in Oracle 11g, yet let this user select from the table of this index?
The anamnesis is as follows: there is a table with one field of BLOB type. Oracle created internal index for that table on that column:
SELECT index_name, index_type, uniqueness,
temporary, generated, secondary, visibility FROM DBA_INDEXES
WHERE table_name = 'SIGNERS_BLOBS_TABLE'
returns
INDEX_NAME INDEX_TYPE UNIQUENESS TEMPORARY GENERATED SECONDARY VISIBILITY
------------------------- ----------- ---------- --------- --------- --------- ----------
SYS_IL0009096175C00002$$ LOB UNIQUE N Y N VISIBLE
And this index I need to hide from a specific user. Yet this same user has to be able to select from that SIGNERS_BLOBS_TABLE.
As far as I understood, Oracle does not support grants on indexes.
#Justin Cave, thank you for all the additional info.
Related
I've seen enough answers to know you can't easily check for columns in SQLITE before adding. I'm trying to make a lazy person's node in Node-Red where you pass a message to SQLITE which is the query. Adding a table if it does not exist is easy.
msg.topic='create table IF NOT EXISTS fred (id PRIMARY KEY);'; node.send(msg);
it occurred to me that adding a table which had the names of the fields would be easy - and if the field name is not in the table.... then add the field. BUT you can't add multiple fields at once - so I can't do this...
msg.topic='create table IF NOT EXISTS fred (id PRIMARY KEY, myfields TEXT);'; node.send(msg);
The problem with THAT is that I can't add this in later, there's no way to check before adding a field it the table exists!
This is what I WANT
msg.topic='create table IF NOT EXISTS fred (id PRIMARY KEY, myfields TEXT);'; node.send(msg);
msg.topic='if not (select address from myfields) alter table fred add column address text';
I just cannot think of any way to do this - any ideas anyone (the idea is that the node-red node would input a table, field and value and if the table didn't exist it would be created, if the field didn't exist it would be created, all before trying to add in the value).
You won't be able to make the ALTER TABLE conditional in the SQL itself. You'll need to handle that from your calling script.
Alternately, simply attempt to add the column to the table and accept failure as an outcome. Assuming the table exists, the only failure reason you could encounter is that the column already exists.
If you'd like to do something more graceful, you can check if the column exists in advance, then conditionally run the SQL from your calling application.
I was not able to find a better title for this.
Branches Users Attendance
----------- ----------- -----------
branchID^ userID^ courseID^
branchName userName userID*
branchID*
Here's my table. Due to company re-structure I need to delete old branches and the users that belong in them. But when my boss wants to see old Attendances he wants to see old userNames even if they don't exist.
What's the best practice here? I'm thinking to add a Disabled column in Branches/Users so they aren't visible on the web page.
A "soft delete" flag is often used to address the requirement to retain both current and logically deleted data. Alternatively, you could move the rows to archive tables for historical reporting.
Having both current and logically deleted rows in the same table is more convenient if you need combined reporting on both. The downside is the presence of the inactive rows can add more overhead for queries of active data only. Much depends on the percentage of inactive rows and the number of rows.
I use this kind of solution:
Making a Log table:
[Log]
ID (bigint IDENTITY(1,1)) PK
Entity_Id (bigint) FK --'Entity' table is list of my tables
Row_Id (bigint) --Is Id of the row of the `Entity`
Kind (int) --0=Create, 1=Modify, 2=Delete, 3=Undelete
actionDate (datetime) --'= GETDATE()'
user_Id (bigint) FK --'User' table is list of users
Now this query gives me the state of the row:
SELECT TOP(1)
Kind,
actionDate,
user_Id
FROM
[Log]
WHERE
Entity_Id = #Entity_Id AND
Row_Id = #Row_Id
ORDER BY
actionDate DESC
As result is:
0 => Created by `user` in `actionDate`
1 => [Last] Modified by `user` in `actionDate`
2 => [Last] Deleted by `user` in `actionDate`
3 => [Last] Undeleted by `user` in `actionDate`
Note :
If you don't want to clear whole database, don't delete any row.
And when you want to delete do it in a mechanism based on relations.
I have suddenly got the following error:
FK_dbo.TimeHoursWorked_dbo.Employee_EmployeeId' is not a constraint.
Could not drop constraint. See previous errors
I dont get it as there are no tables called dbo.TimeHoursWorked or dbo.Employee (I do have tables TimeHoursWorked and Employee.
You do actually have tables called
dbo.TimeHoursWorked and dbo.Employee..
dbo stands for Database Owner, and each table that does not have an owner specified, gets assigned to dbo.
A fully qualified SQL table is
<databaseName>.<owner>.<tableName>
You can use SELECT * FROM Employee which assumes the current database or you can use SELECT * FROM Payroll.dbo.Employee which looks in the Payroll database for a table called Employee owned by the database owner
In case you have several tables inside any sqlite database how could the get the information that they have an auto increment primary key or not?
For instance I am already aware that you could get some info concerning the columns of a table by simply querying this: pragma table_info(tablename_in_here)
It would be much better to get the auto increment column dynamically rather than setting up each corresponding model inside the source code with a boolean value.
Edit:
Let me use this table as an example:
CREATE TABLE "test" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"name" TEXT NOT NULL
)
and this is the result table after executing pragma table_info("test")
cid | name | type | notnull | dflt_value | pk
0 | id | INTEGER | 1 | null | 1
1 | name | TEXT | 1 | null | 0
As you can see there is no information whether the id column is autoincrement or not
Edit2:
I looking for a solution that involves sqlite directly through a statement.
Special situations where the sqlite3 command in the terminal can be used to somehow parse the required information from inside are not acceptable. They do not work in situations where you are not allowed to execute commands in a terminal programmatically. Like in an Android app.
Autoincrementing primary keys must be declared as INTEGER PRIMARY KEY or some equivalent, so you can use the table_info date to detect them.
A column is an INTEGER PRIMARY KEY column if, in the PRAGMA table_info output,
the type is integer or INTEGER or any other case-insensitive variant; and
pk is set; and
pk is not set for any other column.
To check whether the column definition includes the AUTOINCREMENT keyword, you have to look directly into the sqlite_master table; SQLite has no other mechanism to access this information.
If this query returns a record, you have the AUTOINCREMENT keyword somewhere in the table definition (which might return a wrong result if this word is commented out):
SELECT 1
FROM sqlite_master
WHERE type = 'table'
AND name = 'tablename_in_here'
AND sql LIKE '%AUTOINCREMENT%'
You can parse the output of .schema. That will give you the sql commands as you used them to create your tables. If autoincrement was declared, you will see it in the output. This has the advantage that it will list all your tables too.
I am trying to create a trigger such that if i am inserting some values in 1st table than the two field of the 2nd table automatically updated.
case is that i have a table in which i'm storing user details
First Table
1st name | last name | userId | password | adress | email
and 2nd login table which have two field
Second Table
userId | password
now i want if i change value of password in 1st table is automatically reflect in the 2nd table what is the query for that.
as long as the userid and password for the second table are mapped as foreign keys to the first table, i think you should be able to set "on update cascade" on the rows
you can do like this....
CREATE TRIGGER trgTest ON Test
FOR INSERT
AS
INSERT Test2
(Id, value)
SELECT Id, Value
FROM Inserted
or if you're using stored procedures you can easily manage this
CREATE PROCEDURE sp_Insert
#Value varchar(10)
AS
insert into table1 (...,...) values (#value,...)
insert into table2 (...,...) values (#value,...)
You've mostly answered your own question, Prakash. Check out the MSDN documentation on triggers for the specific syntax you need. Jon's comment in regard to the duplication of data points out that your schema is somewhat denormalized so you may want to take a look at changing that unless it's required for your situation.
From MSDN
INSERT INTO auditEmployeeData
(audit_log_type,
audit_emp_id,
audit_emp_bankAccountNumber,
audit_emp_salary,
audit_emp_SSN)
SELECT 'NEW',
ins.emp_id,
ins.emp_bankAccountNumber,
ins.emp_salary,
ins.emp_SSN
FROM inserted ins