dropping a schema with a badly chosen name in sql - sql

How to drop a schema which has a an additional space in its name? When listing out the schemas it shows up as BABBLER GROUP. But when trying to drop (sys as sysdba) using drop user BABBLER GROUP CASCADE; it shows error.

Use quotes; e.g. drop user "BABBLER GROUP" CASCADE
The same is true for any object with a space in its name.
NB: Per commments here: https://stackoverflow.com/a/13798120/361842
Some tools aren't compatible with this feature; SQL Plus should be.
Oracle documentation on the same here: https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements008.htm

Related

Is it possible to alter schema of a database I am not connected to?

Is it possible to alter schema of a database I am not connected to? More specifically I need to change an owner of a schema (but it doesn't matter for the questions' sake).
As documentation says schemata can be altered using a clause like:
ALTER SCHEMA name OWNER TO { new_owner | CURRENT_USER | SESSION_USER }
and it sure works, but only on a database I am currently connected in.
Sure I can reconnect to the other database and do it manually, but I am interested whether it is possible to do it from a connection to another (typically postgres) database. It would be quite helpful for automation processes.
I have tried something like:
ALTER DATABASE ALTER SCHEMA name OWNER TO ...
ALTER SCHEMA "db_name".name OWNER TO ...
But without success - so I am interested whether it is possible at all.
I tried to search for this information using one popular search engine and StackOverflow search feature as well. Unsuccessfully - hence the question.
As #a_horse_with_no_name and #JacobH pointed out in comments it is not possible to alter schema of a database you are not currently connected to.
So I ended up using a command like this in order to achieve the schema alteration:
psql $PG_DATABASE -c "ALTER SCHEMA \"<schema-name>\" OWNER TO $PG_USER";

SQL Server 2008 R2 how to change dbo.tablename to Domain\UserName.T_TableName

Question: when I create a table (T_TableName) using SQL Server Management-Studio, it always creates the table as
dbo.T_TableName
instead of
Domain\UserName.T_TableName
What's wrong ?
It is also known as Database Owner.
Database Owner is the default schema in SQL Server.
Database Owner offers simplified ways to group objects.
dbo is a special schema - it is is present in every database and, typically, it is the default schema for users. It stands for "database owner". If you do not explicitly specify a schema when you refer to an object,
SQL Server will go to the default schema. This is perhaps why you sometimes see this schema and sometimes not. NOTE that it is typically considered bad practice not to explicitly state the schema when referring to an object, so whereas you are keen to not qualify all objects with the schema name, if I got hold of your code I would add the schema name in.
Answer is Reffered From one of my Favourite author :
See
These are some link Please refer this also.
Click Here

CREATE and DROP database won't work [duplicate]

This question already has answers here:
In psql, why do some commands have no effect?
(2 answers)
Closed 9 years ago.
I want simply drop some databases and after that create a new one.
Within postgresql version 9.1, running these commands first to create:
postgres=# createdb [dbname]
or
postgres=# CREATE DATABASE name
as described here Postgresql Documentation.
Now, to drop away some databases:
postgres=# DROP DATABASE name
as described here as well Postgresql Documentation.
They all didn't work. What am I missing?
You forgot the semicolons.
postgres=# DROP DATABASE name;
SQL commands may carry on over multiple lines, and are only sent to the server when you end them with a semicolon. That's why the prompt changes:
postgres=# DROP DATABASE name
postgres-#
It might be a good idea to take a look through the tutorial.
Additionally createdb isn't an SQL command. It's a shell utility command that wraps CREATE DATABASE for convenience.
See also:
Can't delete database
In psql, why do some commands have no effect?
I think you have to be a superuser because accroding to the documentation :
for create a new database :
To create a database, you must be a superuser or have the special
CREATEDB privilege. See CREATE USER.
for drop a database
DROP DATABASE drops a database. It removes the catalog entries for the
database and deletes the directory containing the data. It can only be
executed by the database owner.
Read this tutorial, it will help you.

Db2 drop schema contents along with schema at once

Is there a query in db2 9.7 control center wherein I can't DELETE(DROP) all the contents of my schema (including the schema) at once?
My other option is to drop/delete the objects first and then DROP schema..
But I want to DROP THE ENTIRE SCHEMA WITH ALL OBJECTS at once.
DROP SCHEMA <schema_name> CASCADE/RESTRICT didn't work for me.
The ADMIN_DROP_SCHEMA procedure is what you're looking for.
The ADMIN_DROP_SCHEMA procedure is used to drop a specific schema and all objects contained in it.
http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.admin.doc/doc/r0022036.htm
First drop all the tables in the schema.
Then try to delete the schema using
DROP SCHEMA SCHEMA_NAME RESTRICT
webchain.in have sample java program, explains how to delete the schema using java program
in case drop schema fails after dropping all the tables with the error SQLCODE=-551, SQLSTATE=42501, try command
grant dbadm on database to USER_NAME

how to drop user defined database in sql server 2005?

I am trying to drop a user-defined database, like so:
create database demo;
drop database demo;
But I get the error
Cannot drop the database 'demo',
because it does not exist or you do
not have permission.
One way to sort this out might be to run
SELECT name FROM sys.databases
to see if the database does exist.
Some helpful tips from MSDN:
To use DROP DATABASE, the database
context of the connection cannot be
the same as the database to be
dropped. You could change your
context to, for example USE master
before running DROP
To execute DROP DATABASE, at a
minimum, a user must have CONTROL
permission on the database.
You might find some other useful information there that applies to your specific situation.
create database demo;
drop database demo;
In the above code, if the database is deleted and again tried to delete the database which does not exists will give you the error as you mentioned