Monday, November 24, 2014

Database Mail configuration


1. Open the SSMS and right click on the Database Mail in Management portion. Click on the Configure Database Mail.






2. Click Next on the wizerd.

















3. Select Set up Database Mail by performing the following tasks and click on the Next.


4. Type Profile name and select Add.. button.
 5. Click on New Account.
































6. Type Account name, Email address, Display name, Reply e-mail and Server name. Then click ok.


















7. Select created profile name Default. Select Next.

















8. Test default database mail by executing following store procedure.

EXEC msdb.dbo.sp_send_dbmail 
@recipients = 'parvez.nawaz@gamil.com',
    @subject = 'Test mail from UAT',
    --@profile_name = 'AMS Development',
    @query = 'select getdate()',
    @attach_query_result_as_file = 0






Wednesday, November 5, 2014

List all the tables in a database

SELECT * FROM sysobjects WHERE xtype='U'

Here is a list of other object types you can search for as well:
  • C: Check constraint
  • D: Default constraint
  • F: Foreign Key constraint
  • L: Log
  • P: Stored procedure
  • PK: Primary Key constraint
  • RF: Replication Filter stored procedure
  • S: System table
  • TR: Trigger
  • U: User table
  • UQ: Unique constraint
  • V: View
  • X: Extended stored procedure

In SQL Server 2012, you can use

SELECT * FROM information_schema.tables where table_type='BASE TABLE'

You can also use

select * from sys.tables