Performing catalog operations
Applies to: .NET Framework .NET .NET Standard
To execute a command to modify a database or catalog, such as the CREATE TABLE or CREATE PROCEDURE statement, create a Command object using the appropriate SQL statements and a Connection object. Execute the command with the ExecuteNonQuery method of the SqlCommand object.
Example
The following code example creates a stored procedure in a Microsoft SQL Server database.
// Assumes connection is a valid SqlConnection.
string queryString = "CREATE PROCEDURE InsertCategory " +
"@CategoryName nchar(15), " +
"@Identity int OUT " +
"AS " +
"INSERT INTO Categories (CategoryName) VALUES(@CategoryName) " +
"SET @Identity = @@Identity " +
"RETURN @@ROWCOUNT";
SqlCommand command = new SqlCommand(queryString, connection);
command.ExecuteNonQuery();