Thursday, August 4, 2022

How to rename a database in the MS SQL server:


Use the below code to rename a database in the MS SQL server - 

USE master; GO ALTER DATABASE Database01 SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO ALTER DATABASE Database01 MODIFY NAME = Database02 ; GO ALTER DATABASE Database02 SET MULTI_USER GO



 How to read a JSON file and validate the response against the schema.

Install the following requirements:

  • pip install jsonschema

Use the below code to read a JSON:

def readJSONFile(fileName):
        data = open(fileName)
        jsonData = json.load(data)
        return jsonData

Use the below code to validate a JSON schema:

def validate_schema(json_data, json_schema):
        try:
            validate(instance=json_data, schema= json_schema)
        except jsonschema.exceptions.ValidationError as err:
            assert False, "JSON schema is not matching, Please check"