get schemas in a specific databse in ms sql server - sql

I need to get the schemas list in specific database in MS SQL server, not all schemas list in entire MS SQL server
EX:
i will get list of Db's like A,B,C from ms sql server.Now i need to fetch all schema list from A
I need a query for that
can i get some help here

This can be accomplished using the sys.schemas catalog view:
USE A;
SELECT name
FROM sys.schemas;
3-part name example:
SELECT name
FROM A.sys.schemas;

You can obtain all schemas from specific database like this
USE Database_Name
SELECT * FROM sys.schemas
Read link below to have a better understanding
How do I obtain a list of all schemas in a Sql Server database

Related

How to retrieve all the tables from an sql linked server

I have an sql linked server whose data I can access using openquery, but I have no idea of how to see the tables of that database, hence i cant do much.
I only have a query
SELECT * FROM OPENQUERY(MYSERVER, 'SELECT * FROM SERVXML.DATA AS A WHERE A.DATAID = 2355')
Which returns some stuff.
But otherwise how can I see all the info in MYSERVER? I mean all the tables more specifically.
I have tried using this
EXEC sp_tables_ex 'MYSERVER';
With no result.
I'm a little confused. If you have a linked server, then you can just access the tables using a four-part naming convention: ...table.
This is explained in the documentation.
You can see the linked servers using metadata tables and views. For instance:
select *
from <server>.<database>.INFORMATION_SCHEMA.TABLES

How to get list of all databases and its respective users list in single query

I have searched online and found few queries where I can list users of current database but I want to return all databases and its respective users list in single query.
I am using SQL Server 2017.
How to do that?
Cursor to get database list -> Dynamic SQL to change database context and select from sys.database_principals in the respective database
You can also create a temp table beforehand and insert the result of the dynamic sql into it so you can return all results in a single set

I need to compare column structure of two tables in different databases but on the same instance in SQL Server 2016

I need to compare column structure of two tables in different databases but on the same instance in SQL Server 2016!
Use System Information Schema Views. This should get you started:
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
Use this query to get information of column structure in a database and compare against another db
use DB
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='YourTableName'
This is external software, but unless you have Visual Studio premium where the functionality is built in, you can use something like Red Gate Schema Compare as a trial version to compare and generate a script to synchronise your tables, stored procedures etc.

How can I query the list of database roles in a SQL Server 2000 database?

In Sql Server 2000, is it possible to return, via SQL query, a complete list of database roles that exist in a given database?
I know it is possible to see these roles by expanding the Security, Roles, and Database Roles nodes in SQL Server Management Studio, but I'd like to get them through a query that I can parse programmatically.
To clarify, I'm not looking for a list of users with their roles, but just the list of roles themselves.
Every database in SQL Server 2000 has a sysusers system table
Probably something like
Use <MyDatabase>
Select
[name]
From
sysusers
Where
issqlrole = 1
will do the trick
With our SQL Server 2016 this works for me
Use Sandbox
Select
name, principal_id
From
sys.database_principals
Where
type = 'R' and principal_id < 16384
where Sandbox is the name of my database.
(I'm using SQL with ESRI ArcGIS Enterprise 10.6.)

how to obtain a list of schemas in intersystems cache?

I'm connecting to a Caché database using the ODBC driver, and I want to do a query to obtain a list of schemas. In Microsoft SQL Server I can use a query like this:
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
How can I do this in Caché? I'm also using ADO.NET schema collections, but the schemas don't seem to be available there.
The schema %dictionary has the tables you are looking for. You could select from %dictionary.compiledclass