Posts

Showing posts from January, 2019
DDL OPERATIONS: The various DDL commands are CREATE, ALTER and DROP.   Let us learn about each DDL Command one by one with examples. CREATE Statement:   The CREATE statement in SQL is used to create the database and the database objects like Tables, Views, Sequences, etc. Let us see how a database and table are created in SQL. Creating a database in SQL:   Syntax: CREATE DATABASE DatabaseName; Example: CREATE   DATABASE  Demos;     On executing this query, a database named "Demos" is created.   Creating Table in SQL:   Database is a collection of related tables and other objects. This implies that a table is a part of the database. Now, we have created the "Demos" database. And, we need to create a "Students" table in this database. By default, the master database is selected. Select Demos database from the dropdown list or alternatively you can use the following command: Use Demos;   This command will instru
Image
General purpose queries: Query 1: Retrieve List of All Database   EXEC  sp_helpdb     Query 2: Display Text of Stored Procedure, Trigger, View   exec  sp_helptext @objname =  'Object_Name'      Query 3: Get All Stored Procedure Relate To Database   SELECT   DISTINCT  o. name , o.xtype      FROM  syscomments c      INNER   JOIN  sysobjects o  ON  c.id=o.id      WHERE  o.xtype= 'P'      To retrieve the View use “V” instead of “P” and for functions use “FN.   Query 4: Get All Stored Procedure Relate To Table   SELECT   DISTINCT  o. name , o.xtype      FROM  syscomments c      INNER   JOIN  sysobjects o  ON  c.id=o.id      WHERE  c.TEXT  LIKE   '%Table_Name%'   AND  o.xtype= 'P'      To retrieve the View use “V” instead of “P” and for functions use “FN.   Query 5: Rebuild All Index of Database   EXEC  sp_MSforeachtable @command1= "print '?' DBCC DBREINDEX