SQL Truncate, Delete, Drop advise

后端 未结 6 1588
礼貌的吻别
礼貌的吻别 2021-01-15 03:17

I have a table in a SQL db that I want to remove the data from? I want to keep the columns though.

e.g. my table has 3 columns, Name, Age, Date. I don\'t want to rem

6条回答
  •  不思量自难忘°
    2021-01-15 04:04

    We can rollback the data in conditions of Delete, Truncate & Drop. But must be used Begin Transaction before executing query Delete, Drop & Truncate.

    Here is example :

    Create Database Ankit
    
    Create Table Tbl_Ankit(Name varchar(11))
    
    insert into tbl_ankit(name) values('ankit');
    insert into tbl_ankit(name) values('ankur');
    insert into tbl_ankit(name) values('arti');
    
    Select * From Tbl_Ankit
    
    /*======================For Delete==================*/
    Begin Transaction
    Delete From Tbl_Ankit where Name='ankit'
    
    Rollback
    Select * From Tbl_Ankit
    
    /*======================For Truncate==================*/
    Begin Transaction
    Truncate Table Tbl_Ankit 
    
    Rollback
    Select * From Tbl_Ankit
    
    /*======================For Drop==================*/
    Begin Transaction
    Drop Table Tbl_Ankit 
    
    Rollback
    Select * From Tbl_Ankit
    

提交回复
热议问题