This Question is Answered 

    anon

    How Can A Table Be Removed From A Database?

    asked 2 years ago

    Can't find what you're looking for?

    Ask a Question, Get an Answer ASAP


    Date | Rating

    Answers


    In order to delete a complete table from the database,you can use the SQL drop statement. The syntax for this command is as follows:

    DROP objectType objectName

    For example, the statement to remove a table named "Students" from the database would be

    DROP TABLE Students;

    If you want to keep the table structure, but wish to remove the records, an SQL delete statement would be used. It is important to specify a condition for deletion, otherwise all the records will be removed. The delete statement has the following syntax

    DELETE from tableName [WHERE condition]

    For example, the statement to remove all the students with grade F would be,

    DELETE from StudentGrade where Grade = "F";

    Execution of this command would delete the records that fulfil the [WHERE condition]. Omitting the WHERE clause would result in all the records from the table to be removed.

    Before executing a delete statement, it is important to check for constraints such as referential integrity. If referential integrity is implemented, executing a delete statement would trigger linked records from other tables to be deleted as well. If referential integrity is not implemented, records in linked tables would have to be removed before a DELETE command could be executed.

    answered 2 years ago   

    New Comment

    1000 words left


      A database may consist of several tables. These tables may be interlinked with each other. Before removing the table from the database we must insure that these table are not linked with other table by a relation. If the relation exits than we must remove the relation between the tables. We will look to both steps.

      To drop a table from the database we can use the following SQL command.
      DROP TABLE table_name
      This command will delete the table from the database.
      To drop the relations from the table we can use.
      ALTER TABLE table_name DROP PRIMARY KEY
      This command will drop the primary key constraint from the given table.

      ALTER TABLE table_name DROP CONSTRAINT field_name
      The command will drop the foreign key constraint on given column of the specific table
      By dropping the Unique and primary key constraints drops the associated indexes.
      After removing all the constraints we can delete the table. The data in the table will be lost.
      We can also remove the Indexes and Views.

      To remove an index we can use the following command.
      Drop Index index_name
      It will remove the index.

      To remove a view we can use the following command
      Drop View view_name
      It will remove the view

      answered 2 years ago   

      New Comment

      1000 words left

      Categories

      What is Blurtit ?

      Ask questions on any topic, get great answers from real people for FREE. Blurtit has hundreds of thousand of members so your sure to get the answer your looking for.

      Ask a Question.