The following query returns the members of the database roles.
SELECT DP1.name AS DatabaseRoleName,
The following query returns the members of the database roles.
SELECT DP1.name AS DatabaseRoleName,
The [util].[SearchAll]
stored procedure searches for a specified string (@strFind
) in the following database objects:
Procedures
Views
Functions
Table Columns
@strFind
: The string to search for within the database objects. Type: VARCHAR(MAX)
CREATE PROCEDURE [util].[SearchAll]
(@strFind AS VARCHAR(MAX))
AS
BEGIN
SET NOCOUNT ON;
--TO FIND STRING IN ALL PROCEDURES
BEGIN
SELECT OBJECT_NAME(OBJECT_ID) SP_Name
,OBJECT_DEFINITION(OBJECT_ID) SP_Definition
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%'+@strFind+'%'
END
--TO FIND STRING IN ALL VIEWS
BEGIN
SELECT OBJECT_NAME(OBJECT_ID) View_Name
,OBJECT_DEFINITION(OBJECT_ID) View_Definition
FROM sys.views
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%'+@strFind+'%'
END
--TO FIND STRING IN ALL FUNCTION
BEGIN
SELECT ROUTINE_NAME Function_Name
,ROUTINE_DEFINITION Function_definition
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%'+@strFind+'%'
AND ROUTINE_TYPE = 'FUNCTION'
ORDER BY
ROUTINE_NAME
END
--TO FIND STRING IN ALL TABLES OF DATABASE.
BEGIN
SELECT t.name AS Table_Name
,c.name AS COLUMN_NAME
FROM sys.tables AS t
INNER JOIN sys.columns c
ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%'+@strFind+'%'
ORDER BY
Table_Name
END
END
Example Execution:
To search for the string username
across all specified database objects,
execute the following command:
exec [util].[SearchAll] 'username'
The [util].[SearchAll]
stored procedure is designed to comprehensively
search for a specified string within the definitions of all
stored procedures, views, functions, and table columns in the
database. This is particularly useful for identifying where
specific terms or values are used across various database objects.
Assumptions: stored procedures and tables are created under schema dbo. in case different schema, change the below code accordingly.
--Create Login with a strong password
--Run the below code in Master Database
CREATE LOGIN [sanjeebuser] WITH PASSWORD = 'VeryStrongPa55w0rD1!'
--run the below code in your Selected Database, (optional: run in master database as well)
CREATE USER [sanjeebuser]
FOR LOGIN [sanjeebuser]
WITH DEFAULT_SCHEMA = dbo
GO
--Run the below code in your selected Database. please do not run the code in Master database.
CREATE ROLE [dbstoregeprocedureaccess] AUTHORIZATION [dbo]
GRANT EXECUTE,ALTER,DELETE,UPDATE,INSERT ON SCHEMA::dbo TO dbstoregeprocedureaccess;
GRANT CREATE PROCEDURE TO dbstoregeprocedureaccess;
EXEC sp_addrolemember N'db_datareader', N'sanjeebuser'
EXEC sp_addrolemember N'db_datawriter', N'sanjeebuser'
EXEC sp_addrolemember N'dbstoregeprocedureaccess', N'sanjeebuser'
You'll need Microsoft SQL Server Management Studio to run the below query.
Select the database where you want to run the query against.
Open a new query window and run the below command
DECLARE @SanjeebXsdSchema xml
SET @SanjeebXsdSchema = (SELECT top 1 * FROM [dbo].[BOM_DW_Extract] FOR XML AUTO, ELEMENTS, XMLSCHEMA('sanjeebXsdSchema'))
SELECT @SanjeebXsdSchema
Result:
<xsd:schema xmlns:schema="sanjeebXsdSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" targetNamespace="sanjeebXsdSchema" elementFormDefault="qualified">
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" />
<xsd:element name="dbo.BOM_DW_Extract">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CompanyCode" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="ParentPart" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="ComponentPart" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="ComponentSequence" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="ComponentQuantity" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Reference" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="20" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="BomType" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="20" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="StartDate" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="EndDate" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="ModifiedDate" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
I've assumed you have already configured domain in azure and have created a domain user.
Create Application in app registration
First of all Create an app registration [myssissqlserver01]
Now Go to the sql server (not the database) and on settings menu, click Active directory Admin
Connect to the database using MS Sql server management studio
Once admin is set , Open MS Sql server management studio and connect to the database.
Since we have added user to active directory admin, the user will have access to master database. So we can choose default database to connect,
Create a user in ssis and add to a suitable role
Create a new query window selecting SSISDB database
execute the below queries. Note that the user name should be identical to the Application name created in App registration section . [ myssissqlserver01]create user [myssissqlserver01] from external provider;
exec sp_addrolemember [db_owner],[myssissqlserver01];
declare @n datetime = dateadd(mm,0,getDate())
declare @FirstWeekDayOfMonth int
SELECT @FirstWeekDayOfMonth= CASE
WHEN Datename(dw, Dateadd(dd, -Datepart(dd, @n) + 1, @n)) = 'Saturday' THEN Day(Dateadd(dd, -Datepart(dd, @n) + 3, @n))
WHEN Datename(dw, Dateadd(dd, -Datepart(dd, @n) + 1, @n)) = 'Sunday' THEN Day(Dateadd(dd, -Datepart(dd, @n) + 2, @n))
ELSE Day(Dateadd(dd, -Datepart(dd, @n) + 1, @n))
END
select @FirstWeekDayOfMonth
Note: to find out first day of next month , change first line to dateadd(mm,1,getDate())
1st day of next N month , change the first line to dateadd(mm,n,getDate())
I wanted to add a new sql user "sqluser" in Azure SQL server to access a database "sanjeeb".
Steps to create a new SQL user.
1) Connect to the Azure sql server with existing user using Microsoft SQL Server Management studio
2) Open new query window under Master database
3) Run the below script
CREATE LOGIN [sqllogin] WITH PASSWORD = 'verystrongpassword#1'
Using user secrets in a .NET Web API project to securely manage your database password is an excellent practice. It keeps sensitive info...