Using Enterprise Architect version 13.0.1309, I'm designing a database model to be used with Oracle 12c. I want to generate a DDL script from my model that uses the "new" IDENTITY column type instead of the explicitly created sequences and triggers.
Example:
CREATE TABLE identity_test_tab (
id NUMBER GENERATED BY DEFAULT AS IDENTITY,
description VARCHAR2(30)
);
However, I either can't find the option in EA or it is not supported. Which one is it?
Related
in my database first application (Firebird), the primary keys are not set to identity by default !
how to fix that from the t4 template generation file ?
thanks and good day
Primary keys are not necessarily identity columns, and Firebird 2.5 and earlier doesn't have identity columns. Instead you simulate it with a trigger and a sequence/generator, but this isn't 'detectable' from a metadata perspective (or at least pretty hard to infer correctly). Identity columns will be introduced in Firebird 3.
For the entity framework client for Firebird to recognize the column as identity, you need to add a comment to the column (in the database!) with the text #PK_GEN#, like so:
comment on column yourtable.yourcolumn is '#PK_GEN#'
See also: Generated primary key in Entity Framework model from Firebird
I have a database on azure where clustered indices are required. I would like to use Entity-Framework 6 Alpha 2, because I would like to use the new async features. When I test it on my local machine with SQL Express 2012 everything is fine, but when I try it with my azure database I get the following error:
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
I have no idea what to do, because when I test it with an empty database every primary key is a clustered index.
Any ideas?
Would you add a bit clarification on your situation with "Existing Database on Windows Azure" and using with EF 6? First of all - are you using EF CodeFirst, ModelFirst, DatabaseFirst?
Then if you really have existing database, how did you create it? DB + Schema manually, using some wizard (SSMS, SQL Azure Migration Wizard, EF CodeFirst created it, etc?). How this existing DB ended being in Azure?
Then trace down the full error message, check for which table it happens and manually add the clustered index on that table. It is true that every primary key you create in SQL Server, by default is also a CLUSTERED. But if the table was created first, then the Primary Key was added as separate DDL statement (ALTER TABLE ....) it might not have been created as CLUSTERED.
So, the message is pretty clear - please create clustered index first. Find out which table is SQL Azure complaining about and create a clustered index on it. If it hasn't Primary Key, just add one as CLUSTERD:
ALTER TABLE [dbo].[Individual]
ADD CONSTRAINT [PK_Individual_CustomerID]
PRIMARY KEY CLUSTERED
(
[CustomerID] ASC
)
If it has a primary key - check which columns are included, drop it, and recreate it as clustered.
I have a .NET 4.0 application that uses Entity Framework 4 that connects to a MS SQL 2008 database. The naming convention used is for example table "Clients", fields : "Id", "Id_Order". Now I need to switch from SQL Server to Oracle Server, so I migrated the MS SQL database to oracle database, but the problem is that all the table names and column names are uppercased, so by generating the edmx for oracle(using ODAC), I will have to change in code from "Clients" to "CLIENTS", "Id" to "ID", "Id_Client" to "ID_CLIENT", and it's a lot to change.
The migration was done using the built-in migration tool from Oracle SQL Developer 3.1.07.
A snippet from the generated script:
CREATE TABLE Clients (
I have read that in order to create case-sensitive identifiers you must use double quotes.
So I think the script should be something like this:
CREATE TABLE "Clients" (
Does anyone know a migration tool that perserves names case or at least a general option that I can switch on in the script ?
Why do you need to change the code? The whole point of Oracle being case-insensitive is that you can refer to the table as clients, Clients, CLIENTS, or even clIeNtS, and it will work.
You only use the double-quotes if you want case-sensitivity for some reason, but unless you have table names that are the same apart from case (shudder), you shouldn't need it.
I'm just getting started with PostgreSQL, and I'm new to database design.
I'm writing software in which I have various plugins that update a database. Each plugin periodically updates its own designated table in the database. So a plugin named 'KeyboardPlugin' will update the 'KeyboardTable', and 'MousePlugin' will update the 'MouseTable'. I'd like for my database to store these 'plugin-table' relationships while enforcing referential integrity. So ideally, I'd like a configuration table with the following columns:
Plugin-Name (type 'text')
Table-Name (type ?)
My software will read from this configuration table to help the plugins determine which table to update. Originally, my idea was to have the second column (Table-Name) be of type 'text'. But then, if someone mistypes the table name, or an existing relationship becomes invalid because of someone deleting a table, we have problems. I'd like for the 'Table-Name' column to act as a reference to another table, while enforcing referential integrity.
What is the best way to do this in PostgreSQL? Feel free to suggest an entirely new way to setup my database, different from what I'm currently exploring. Also, if it helps you answer my question, I'm using the pgAdmin tool to setup my database.
I appreciate your help.
I would go with your original plan to store the name as text. Possibly enhanced by additionally storing the schema name:
addin text
,sch text
,tbl text
Tables have an OID in the system catalog (pg_catalog.pg_class). You can get those with a nifty special cast:
SELECT 'myschema.mytable'::regclass
But the OID can change over a dump / restore. So just store the names as text and verify the table is there by casting it like demonstrated at application time.
Of course, if you use each tables for multiple addins it might pay to make a separate table
CREATE TABLE tbl (
,tbl_id serial PRIMARY KEY
,sch text
,name text
);
and reference it in ...
CREATE TABLE addin (
,addin_id serial PRIMARY KEY
,addin text
,tbl_id integer REFERENCES tbl(tbl_id) ON UPDATE CASCADE ON DELETE CASCADE
);
Or even make it an n:m relationship if addins have multiple tables. But be aware, as #OMG_Ponies commented, that a setup like this will require you to execute a lot of dynamic SQL because you don't know the identifiers beforehand.
I guess all plugins have a set of basic attributes and then each plugin will have a set of plugin-specific attributes. If this is the case you can use a single table together with the hstore datatype (a standard extension that just needs to be installed).
Something like this:
CREATE TABLE plugins
(
plugin_name text not null primary key,
common_int_attribute integer not null,
common_text_attribute text not null,
plugin_atttributes hstore
)
Then you can do something like this:
INSERT INTO plugins
(plugin_name, common_int_attribute, common_text_attribute, hstore)
VALUES
('plugin_1', 42, 'foobar', 'some_key => "the fish", other_key => 24'),
('plugin_2', 100, 'foobar', 'weird_key => 12345, more_info => "10.2.4"');
This creates two plugins named plugin_1 and plugin_2
Plugin_1 has the additional attributes "some_key" and "other_key", while plugin_2 stores the keys "weird_key" and "more_info".
You can index those hstore columns and query them very efficiently.
The following will select all plugins that have a key "weird_key" defined.
SELECT *
FROM plugins
WHERE plugin_attributes ? 'weird_key'
The following statement will select all plugins that have a key some_key with the value the fish:
SELECT *
FROM plugins
WHERE plugin_attributes #> ('some_key => "the fish"')
Much more convenient than using an EAV model in my opinion (and most probably a lot faster as well).
The only drawback is that you lose type-safety with this approach (but usually you'd lose that with the EAV concept as well).
You don't need an application catalog. Just add the application name to the keys of the table. This of course assumes that all the tables have the same structure. If not: use the application name for a table name, or as others have suggested: as a schema name( which also would allow for multiple tables per application).
EDIT:
But the real issue is of course that you should first model your data, and than build the applications to manipulate it. The data should not serve the code; the code should serve the data.
I have installed oracle 10g express edition and I did not find the option to
create schema..
Is there a option to create schema in oracle 10g express edition
or else I have to install other oracle 10g..?
To create schema which oracle 10g
I have to install... what?
You don't need to explicitly create schema, Oracle automatically creates a schema when you create a user (see CREATE USER documentation).
If you really want, you can use CREATE SCHEMA statement and issue it through Oracle Express web interface or from SQL prompt.
The CREATE SCHEMA statement can include CREATE TABLE, CREATE VIEW, and GRANT statements. To issue a CREATE SCHEMA statement, you must have the privileges necessary to issue the included statements.
CREATE SCHEMA AUTHORIZATION oe
CREATE TABLE new_product
(color VARCHAR2(10) PRIMARY KEY, quantity NUMBER)
CREATE VIEW new_product_view
AS SELECT color, quantity FROM new_product WHERE color = 'RED'
GRANT select ON new_product_view TO hr;
As zendar said, creating a user automatically creates their schema (in Oracle these are pretty much the same concept).
When you create a Workspace in apex, it will ask you if you want to use an existing schema or create a new one - so that's another easy option you could use.