restore the database to a different collation - sql-server-2008-r2

I tried to find how do I restore the database to a different collation.
For example:
Server collation is Czech_CI_AS
Database, which I backed up, has a collation Czech_CI_AS.
And I need to restore a backup of the database, but with the
collation SQL_Latin1_General_CP437_CI_AI.
Somewhere I'm doing something wrong, will you help me?

As you've discovered, the collation of the original database is preserved in the backup, and so when you create a new database from this backup somewhere else, the original collation comes with it. There is no option on the restore command to change collation during the restore.
You could ALTER DATABASE to a different collation after you have restored the database, but note that this will not change the collation of all the existing objects in the database, you will need to alter the collation of columns in individual tables yourself.
See MSDN:
When you change the database collation, you change the following:
Any char, varchar, text, nchar, nvarchar, or ntext columns in system tables are changed to the new collation.
All existing char, varchar, text, nchar, nvarchar, or ntext parameters and scalar return values for stored procedures and
user-defined functions are changed to the new collation.
The char, varchar, text, nchar, nvarchar, or ntext system data types, and all user-defined data types based on these system data
types, are changed to the new default collation.
You can change the collation of any new objects that are created in a
user database by using the COLLATE clause of the ALTER DATABASE
statement. This statement does not change the collation of the columns
in any existing user-defined tables. These can be changed by using the
COLLATE clause of ALTER TABLE.

Related

if we change the schema of a table in postgress will the sequence gets auto created?

Say we have a schema named : "test", a table in it as below:
CREATE TABLE IF NOT EXISTS test.details
(
id integer NOT NULL DEFAULT nextval('test.details_id_seq'::regclass),
username character varying(50) COLLATE pg_catalog."default" NOT NULL
)
as we could see id column is a Sequence which is already been created in this schema.
now if we create a new schema named "check" and altered details table schema as
create schema check
alter table test.details set schema check
will the sequence be auto created in check schema?
The sequence is an independent database object. If you change the schema of the table, the sequence will remain in the old schema, and the table will continue to use it. You can use ALTER SEQUENCE to change the sequence's schema as well, and the default value will continue to work (PostgreSQL stores the parsed default expression rather than the text).
All that becomes easier if you use identity columns to generate keys: there, you don't have to take care of the sequence. It is created automatically and changes schema with the table.

Create database defnition equivalent from mysql to postgresql

I need to migrate a mysql table to postgresql.
I need an accent and case insensitive database.
In mysql, my database has the next definition:
CREATE DATABASE gestan
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
How do I create an equivalent definition to postgresql?
I have read some posts, but it seems outdated.
create database getan
encoding = 'UTF-8';
There is no direct equivalent for the case insensitive collation _ci in Postgres.
You can define a new ICU collation that uses case insensitive comparison, but it can't be used as a default collation for a database, only for the collation on column level.
Related questions:
Install utf8 collation in PostgreSQL
https://dba.stackexchange.com/questions/183355
https://dba.stackexchange.com/a/256979

default tablespace for schema in DB2

We have got some DDLs for our schema. These DDLs create tables and indexes in a given tablespace. Something like:
CREATE TABLE mySchema.myTable
(
someField1 CHAR(2) NOT NULL ,
someField2 VARCHAR(70) NOT NULL
)
IN MY_TBSPC
INDEX IN MY_TBSPC;
We want to reuse this DDLs to run some integration tests using APACHE DERBY. The problem is that such syntax is not accepted by DERBY. Is there any way to define a kind of default tablespace for tables and indexes, so we can remove this 'IN TABLESPACE' statements.
There is no deterministic way of defining a "default" tablespace in DB2 (I'm assuming we're dealing with DB2 for LUW here). If the tablespaces are not explicitly indicated in the CREATE TABLE statement, the database manager will pick for table data the first tablespace with the suitable page size that you are authorized to use, and indexes will be stored in the same tablespace as data.
This means that if you only have one user tablespace it will always be used for both data and indexes, so in a way it becomes the default. However, if you have more than one tablespace with different page sizes you may end up with tables (and their indexes) in different tablespaces.

Is it safe to change Collation on Postgres (keeping encoding)?

I have a Postgres 9.3 database which, by mistake, has been set to:
but I need it to be:
Since the Encoding doesn't change, it is safe to dump the DB and restore it later (see here) to a database with the new Collation / Character type?
Perfectly safe -- the collation is just telling Postgres which set of rules to apply when sorting text.
You can even set it dynamically on a query basis in the order by clause, and should be able to alter it without needing to dump the database.

how can i change the "character type" of a database in postgresql?

I'm using postgreSQL 9.1
I've set the Collation and the Character Type of the database to Greek_Greece.1253 and I want to change it to utf8
To change the collation I should use this, right?
But how can I change the character type?
Thanks
EDIT
I ment to wright C instead of utf8. I would like to change the Collation and the Character Type to C
You cannot change default collation of an existing database. You need to CREATE DATABASE with the collation you need and then dump/restore your schema and data into it.
If you do not want to recreate the database - you can specify collation for every text collumn in your db.
Here is detailed postgres manual on collations: Collation Support.
First line of this manual page states:
LC_COLLATE and LC_CTYPE settings of a database cannot be changed after
its creation.
CREATE DATABASE, pg_dump, pg_restore