SQL 문 실행

이 샘플은 지정된 데이터베이스 인스턴스에서 SQL 문을 실행하는 방법을 보여줍니다. 이 메서드를 사용하여 관리 쿼리를 실행하거나 데이터베이스 작업을 프로그래매틱 방식으로 자동화합니다.

코드 샘플

C#

AlloyDB에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

using Google.Cloud.AlloyDb.V1;

public sealed partial class GeneratedAlloyDBAdminClientSnippets
{
    /// <summary>Snippet for ExecuteSql</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void ExecuteSql()
    {
        // Create client
        AlloyDBAdminClient alloyDBAdminClient = AlloyDBAdminClient.Create();
        // Initialize request argument(s)
        string instance = "projects/[PROJECT]/locations/[LOCATION]/clusters/[CLUSTER]/instances/[INSTANCE]";
        string database = "";
        string user = "";
        string sqlStatement = "";
        string password = "";
        // Make the request
        ExecuteSqlResponse response = alloyDBAdminClient.ExecuteSql(instance, database, user, sqlStatement, password);
    }
}

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저 참조하기