First insert a few data in my student table, because my table has been created, so there is no SQL statement to create the table, but you can see my previous article:
Http://www.cnblogs.com/Brambling/p/6649350.html
Insert Data SQL statement:
1 Insert intoStudent (s_stuno,s_name,s_sex,s_height)2 Select '001','Xiang Yu','male',' the' Union 3 Select '002','Liu Bang','male',' the' Union 4 Select '003','Mink Cicada','female',' the' Union 5 Select '004','Dawn','male','155' Union 6 Select '005','Less Life','female','175'
Of course, it can also be written as follows, but I am personally accustomed to the above method.
1 Insert intoStudent (S_stuno,s_name,s_sex,s_height)Values('001','Xiang Yu','male',' the')2 Insert intoStudent (S_stuno,s_name,s_sex,s_height)Values('002','Liu Bang','male',' the')3 Insert intoStudent (S_stuno,s_name,s_sex,s_height)Values('003','Mink Cicada','female',' the')4 Insert intoStudent (S_stuno,s_name,s_sex,s_height)Values('004','Dawn','male','155')5 Insert intoStudent (S_stuno,s_name,s_sex,s_height)Values('005','Less Life','female','175')
SQL Server statements insert data from one table into another table, in the following two ways:
First, when the table to be inserted (Student_back) does not exist
1 -- inserting student information in table Student with gender ' male ' into table student_back (not present) 2 Select * into from where S_sex=' male '
Without specifying a specific column, a table like (Student) is automatically created and the data is inserted
Specifying the column to be inserted creates a table from the specified column and inserts the data into
Second, when the table you want to insert itself exists
1 -- Insert the student information of the Student gender as ' female ' into the table Student_back (present) 2 Insert into Student_back (s_stuno,s_name,s_sex,s_height) 3 Select S_stuno,s_name,s_sex,s_height from Student4 where s_sex = ' female '
Because the field s_id is an identity column, you cannot have the inserted value displayed, so you must specify the column to insert.
Earlier, the SQL statement that created the table, the following is the SQL statement that deletes the table:
The exact way to delete a table is drop:
1 Drop Table Student_back
This deletes the table, which removes not only the data from the table, but also the table structure, fields, views, indexes, triggers, and dependent constraints, and so on. This method is used with caution!!!
Truncate
1 truncate Table Student_back
This simply deletes all the data in the table, preserves the table structure, fields, constraints, indexes, and so on, but cannot impose a where condition restriction.
If the table exists FOREIGN key (foreign KEY constraint), you cannot use this method, and you should use a DELETE statement without a where condition, but the TRUNCATE statement executes faster than the DELETE statement.
Delete
1 Delete from where S_stuno='001'
Such deletes also delete data from the table, and you can add a where condition limit and activate the trigger (trigger).
SQL Server inserts data and deletes the data base statement using