|
|
To assist you with managing Microsoft SQL Server databases,
Transact-SQL provides many built-in stored procedures.
|
To rename an object that was created in the current
database, you can call the sp_rename stored procedure. Its syntax is:
sp_rename [ @objname = ] 'object_name' , [ @newname = ] 'new_name'
[ , [ @objtype = ] 'object_type' ]
The object_name is the name of the object you want to
delete.
The new_name is the new name the object will have.
The object_type is option. It allows you to specify
the type of object you are trying to rename.
The sp_rename stored procedure can be used to rename
a table. Here is an example:
USE Exercise;
GO
EXEC sp_rename N'Contractors', N'Employees';
GO
When this code runs, a table named Contractors will have its
name changed to Employees.
The sp_rename stored procedure can also be used to
rename a column or an index. In this case, the name of the object must be
qualified.
To give you the ability to send an email from a database,
Transact-SQL provides the sp_send_dbmail stored procedure. This store
procedure is created in the msdb database. This means that you must
reference it when executing this procedure. It's syntax is:
sp_send_dbmail [ [ @profile_name = ] 'profile_name' ]
[ , [ @recipients = ] 'recipients [ ; ...n ]' ]
[ , [ @copy_recipients = ] 'copy_recipient [ ; ...n ]' ]
[ , [ @blind_copy_recipients = ] 'blind_copy_recipient [ ; ...n ]' ]
[ , [ @subject = ] 'subject' ]
[ , [ @body = ] 'body' ]
[ , [ @body_format = ] 'body_format' ]
[ , [ @importance = ] 'importance' ]
[ , [ @sensitivity = ] 'sensitivity' ]
[ , [ @file_attachments = ] 'attachment [ ; ...n ]' ]
[ , [ @query = ] 'query' ]
[ , [ @execute_query_database = ] 'execute_query_database' ]
[ , [ @attach_query_result_as_file = ] attach_query_result_as_file ]
[ , [ @query_attachment_filename = ] query_attachment_filename ]
[ , [ @query_result_header = ] query_result_header ]
[ , [ @query_result_width = ] query_result_width ]
[ , [ @query_result_separator = ] 'query_result_separator' ]
[ , [ @exclude_query_output = ] exclude_query_output ]
[ , [ @append_query_error = ] append_query_error ]
[ , [ @query_no_truncate = ] query_no_truncate ]
[ , [ @mailitem_id = ] mailitem_id ] [ OUTPUT ]
As you may guess, most of the arguments are optional.
Otherwise:
- The profile_name value must hold a valid for an existing profile.
If you omit this argument, the database engine uses the current user or a
default profile created in the msdb database. If there is no default
profile, you must create one. To do this, in the Object Explorer, expand the
Management node and double-click Database Mail. A wizard would start:
Click Next. If you are trying a new profile, click the first radio
button:

Click Next. This would bring the third page of the wizard:

In the Profile Name text box, enter the desired name. If you want,
type some explanation in the Description text box. To specify an
account that can send emails, click Add and fill out the form. Once
you are ready, click OK. If you want to add another profile, click Add
again, fill out the form, and click OK. On the third page of the
wizard, click Next twice. When the wizard has finished, click Close. |