SQL to get default schema of some database in Netezza? - sql

We can change the default schema of a database using alter command. Is there some SQL command to get default schema?

You can check this via the _V_DATABASE view.
TESTDB.ADMIN(ADMIN)=> select database, defschema from _v_database where database='TESTDB';
DATABASE | DEFSCHEMA
----------+-----------
TESTDB | ADMIN
(1 row)

Related

PostgreSQL, Update from Insert into sql

I have 2 db, I have to update a table called "my_table" from db 1 to db 2.
Is there a way to dump the table from db1 and use that sql to update the table on the db2?
All I have is a sql file with INSERT INTO but I need an UPDATE
How could I do it?
Using DB link: dblink executes a query (usually a SELECT, but it can be any SQL statement that returns rows) in a remote database.
you can refer this official link(https://www.postgresql.org/docs/current/contrib-dblink-function.html) for DB link creation

Microsoft SQL Server 2005: Create alias for database

How can I create alias name to my database in SQL Server 2005?
For example: DB1 and its alias DB2, it's same DB, but with two names.
Or can I do replication, mirroring, syncing or anything other inside server from one DB to another?
You can do replication from one database to another database on the same machine. You can also copy data directly without having to create an alias. For instance if you had a table named Users in DB2 and a Users table in DB1 and they are the same schema you could easily just do
INSERT INTO DB1..Users
select * from DB2..Users
Now, a synonym would allow you to use a table from DB2 as if it was a table in DB1 so for instance if you have a table named Products in DB2 you could do
use DB1
GO
CREATE SYNONYM [dbo].[Products] FOR [DB2].[dbo].[Products]
GO
-- Now the following would give you the same result
select * from DB2..Products
select * from Products
For more information on synonyms see here

Postgres source SQL for existing table

I need to extract the source SQL for an existing table in postgres. Is it is possible?
Example: If I have a customertable, created in pgadmin, with 2 columns: id (integer), name (text). Is there way I can extract/get the CREATE function for this existing table, so I get a SQL with “CREATE TABLE customer ...” without having to write the whole SQL of the table in hand?
pgadmin (III,4):
right click on table name -> Scripts-> CREATE sript
psql:
pg_dump -s -t table_name

SQL Server 2008 - permission denied in database 'master'

I am new to SQL Server and I wanted to create my first table there.
create table Employee
(
ID smallint not null
)
I use SQL Server 2008 R2 and Windows Authentication.
when I execute , it says :
CREATE TABLE permission denied in database 'master'.
Thanks!
Seems you're trying to create the table in master database where you may not have permission to create table. However, to create your target database please follow below steps:
a. At your SQLQuery editor choose your target database (Available Database drop down list) and execute your sql query.
Or
b. Try with below statement:
USE YourTargetDatabaseName
GO
CREATE TABLE Employee ( ID SMALLINT NOT NULL)
GO
I don't think you want to create a table in the master database.
Did you create a new database first? If so, use this:
USE [MyNewDatabaseName]
GO
create table Employee ( ID smallint not null )
GO

Postgres: Is there a way to tie a User to a Schema?

In our database we have users: A, B, C.
Each user has its own corresponding schema: A, B, C.
Normally if I wanted to select from a table in one of the schemas I would have to do:
select * from A.table;
My question is:
Is there a way to make:
select * from table
go to the correct schema based on the user that is logged in?
This is the default behavior for PostgreSQL. Make sure your search_path is set correctly.
SHOW search_path;
By default it should be:
search_path
--------------
"$user",public
See PostgreSQL's documentation on schemas for more information. Specifically this part:
You can create a schema for each user with the same name as that user. Recall that the default search path starts with $user, which resolves to the user name. Therefore, if each user has a separate schema, they access their own schemas by default.
If you use this setup then you might also want to revoke access to the public schema (or drop it altogether), so users are truly constrained to their own schemas.
Update RE you comment:
Here is what happens on my machine. Which is what I believe you are wanting.
skrall=# \d
No relations found.
skrall=# show search_path;
search_path
----------------
"$user",public
(1 row)
skrall=# create schema skrall;
CREATE SCHEMA
skrall=# create table test(id serial);
NOTICE: CREATE TABLE will create implicit sequence "test_id_seq" for serial column "test.id"
CREATE TABLE
skrall=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------+----------+--------
skrall | test | table | skrall
skrall | test_id_seq | sequence | skrall
(2 rows)
skrall=# select * from test;
id
----
(0 rows)
skrall=#