Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

How to Create MS SQL Server Database Using Microsoft SQL Server Management Studio and T-SQL?

This article explains How to create a database in Microsoft SQL Server using the MS SQL SERVER Management Studio and T-SQL. This article explains the step by step method to create the database using the Management Studio, beginners in MSSQL can easily create the database using this tutorial.
  1. Open Microsoft SQL Server Management Studio.
  2. Connect to the database engine using database administrator credentials.
  3. Expand the server node.
  4. Right click Databases and select New Database.
  5. Enter a database name
  6. Add / Change Data file path
  7. Add / Change Log file path
  8. Click OK to create the database.






Create database SQL syntax for MS SQL Server is as follows.



How to show stored procedure code in PostgreSQL using SQL query in PgAdmin 4

Use this system table "pg_proc" to get the procedure source and other details from PgAdmin 4 query console.

How to show stored procedure code using SQL query
SELECT prosrc FROM pg_proc WHERE proname = 'procedurename'
The above quey does not display the complete proc source including the CREATE FUNCTION. For that we need to use system function "pg_get_functiondef()". This function display entire procedure source.
SELECT pg_get_functiondef((SELECT oid FROM pg_proc WHERE proname='procedurename')
		            );
How to show stored procedure code using sql query

Shortcut to show PostgreSQL function code in PgAdmin

What is the command to find script of a existing function in postgresql? The answer is pg_get_functiondef(). As we are utilizing sp_helptext [procedure name] to get the SP script in Sql server, In postgresql using this pg_get_functiondef() command, we can enable macro for using shortcut keys in Postgre SQL PgAdmin III. For enable macro open PostgreSQL query window select the "Manage macros" menu from "Macros".
We can use any key in the macro section. If we want to use shortcut key as Ctrl+1, simply click on the Ctrl+1 key in macro then give a name for the macro and copy and paste the below mentioned code. After saving the macro you can use Ctrl+1 to display the full Postgre SQL function code.

DO
$$
DECLARE v_Inputtext TEXT;
        v_output text;

BEGIN
        v_Inputtext    := (SELECT lower('$SELECTION$'));
        v_output       := (SELECT pg_get_functiondef(oid) FROM pg_catalog.pg_proc WHERE proname = v_Inputtext);
         
        RAISE NOTICE '%',v_output;


END;
$$

Please visit other related articles

PostgreSQL: Enable macro in PgAdminIII
PostgreSQL: Export PostgreSQL data in to excel file
PostgreSQL: How to restrict the user access to the databases in Postgresql based on the permission
PostgreSQL: List table details using Alt+F1 in PostgreSQL
PostgreSQL: How to get ROW_COUNT of last executed query in PostgreSQL like MS SQL @@ROWCOUNT ?
novicetechie.com

Log Shipping - How you can convert the secondary database into primary
This topic explains the log shipping if the primary database is suspected or corrupted and how you can convert the secondary database into primary database.
To recover a database without restoring (to be done in the master data base)
Execute the RESTORE DATABASE statement, specifying:
  • ·   The name of the database to be recovered
  • ·   The RECOVERY clause


  /* To recover a database without restoring (to be done in the master database)  
   Execute the RESTORE DATABASE statement, specifying:
   The name of the database to be recovered
   The RECOVERY clause

Example
For example, you can recover the database, AdventureWorks2008R2, as in a restore operation without restoring data
*/

-- Restore database using WITH RECOVERY.
RESTORE DATABASE AdventureWorks2008R2
   WITH RECOVERY