I use oracle as my database.
I am confused with the concept between schema and database. I looked around here and couldn't find any explicit defined example.
Suppose we have a QA, DEV and production environment and suppose I have three QA environments. Between the three QA environment, will they generally have different database or different schema?
Suppose those three different QA environments have different data in each environment. And suppose I want to create a new fourth QA environment and want to copy a table (lets call this table foo) from one of the already existing QA environment (lets call this environment QA_1) to the new QA environment (lets call this QA_NEW). Will I be copying the schema table foo from QA_1 to QA_NEW or will I be copying the database table from QA_1 to QA_NEW?
You will want to copy the entire database to the new environment so that all environments match.
A schema is similar to a namespace. A database can have multiple namespaces and you'll likely want to copy all.
databases are physical (data files, blocks. etc.).
schemas are usernames (owners) of logical storage objects (tables, mviews, etc.) within the database
In your case, you have 3 QA databases (QA_1, QA_2 .. QA_N), each with their own schemas - likely of the same schema names (usernames). You'd be copying the database.schema.table to another database.schema.table
QA_1.myschema.foo -> QA_2.myschema.foo
You'd say "Foo table lives in the QA_1 database and is owned by the 'myschema' schema."
Related
I have an old ERP, which handled many organizations in a single db with a suffix on the tables. Lets say the db name is ORG and the tables look like CLIENTS01, CLIENTS02, CLIENTS03.
The new ERP connects to one database per organization.
The sad thing is I need to use both ERPs, so I need to replicate SAME DB WITH MULTIPLE NAMES: ORG01, ORG02, ORG03.
I was thinking for mirroring but this will increase database workload.
I looked for aliases but didn't find the way to make it work on the same instance.
I tried to create new database and then attach same file MDF file without success.
What would be the simplest way to just create 3 new databases connecting to the same database (1 database, multiple names)?
Not:
DROP -> CREATE
I need:
COMPARE -> ALTER
I have a test and a production database, the data withing these two are different but the schemas should be the same.
I need something like a production script or a tool or a method which compare these two dbs schema and sync them. I'm coding in nodejs and the thing is I haven't used tools like an ORM or db-migrate, I've created the database using MYSQL-workbench and it costs a lot to write every alter query. there must be an easier way.
I have a Postgres database with some schemas (all have the same structure), I want to know if there is the possibility to change the structure (Table names, new columns etc) for all the schemas in the same database. Is it possible or what's the purpose of the schemas in a database?
Thanks.
I'm going to focus on the second half of your question, because I think it'll answer the first half (and I'm not sure I understand the first half).
what's the purpose of the schemas in a database?
This confused me when I first switched from MySQL to PostgreSQL. A Postgres schema is essentially the same as a MySQL database. In fact, according to the MySQL Reference Manual:
In MySQL, physically, a schema is synonymous with a database.
That begs the question of what is a PostgreSQL database, then? From the PostgreSQL Documentation:
More accurately, a database is a collection of schemas and the schemas contain the tables, functions, etc. So the full hierarchy is: server, database, schema, table (or some other kind of object, such as a function).
So a PostgreSQL database is essentially a collection of schemas? Seems kind of pointless, why do we need that step in the hierarchy? Let's take a look at the docs for a PostgreSQL schema:
A PostgreSQL database cluster contains one or more named databases. Users and groups of users are shared across the entire cluster, but no other data is shared across databases. Any given client connection to the server can access only the data in a single database, the one specified in the connection request.
A database contains one or more named schemas, which in turn contain tables. Schemas also contain other kinds of named objects, including data types, functions, and operators. The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable. Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database he is connected to, if he has privileges to do so.
So, in PostgreSQL, a schema contains tables, functions, etc. And a database manages user/group connectivity and access/roles to specific clusters of schemas. Typically, I work under one database and have information broken into schemas to segment information.
I'm using two databases test and prod in the same SQL Server instance. The databases share the same data structure but contains different data, is there an easy way to synchronize the structure between the two so if I modify a table in test automatically update also the same table in prod?
You could write a trigger on the table in test which uses a MERGE to update the table in prod...
I would be careful of persisting changes made in a test environment to a prod environment automatically though.
I am creating a smaller sized database in Microsoft SQL Server 2012 to keep run data from machines. The company has production machines and R & D machines. I would like to use the same table for production and R&D with a Type field specifying what the run was for simplicity. I have two schemas (prod and r_d). The permissions for the production and r_d schemas will be different. Is it possible to create a table that belongs to more than one schema? I know you can have the same table name in multiple schemas, but this creates separate objects. I would like to have the one table object to belong to multiple schemas.
Example:
CREATE TABLE db_name.prod.r_d.table_name
Consider creating a synonym in one the of schemas, referencing the other schema table:
CREATE SYNONYM r_d.table_name FOR prod.table_name;
No, but you can create a view in each schema on to a single table that filters the rows
When you said Development and Production. You should consider using separate database and as we go separate server !
For sampling the data you could use a backup of the production database. If you don't want the dev team to have access to production data (avoid data leak), they have to generate their sample data themselves.
Using Synonym or View in your case looks like a bad and dangerous practice !