------Backup Restore--right-click database---Tasks--backup: Backs up data to a. Bak end folder without affecting the database's normal operation--restore: Restore bak file to database-----detach, attach--Detach: Detach a database from a database service--Attach: Attach the database MDF file to the database service--triggers: A special kind of stored procedure where triggers are triggered by actions on database tables only ' additions and deletions '--stored procedures are performed by execCreate TriggerStudent_insert--Create a trigger onStudent--Specify the table where the trigger resides for Insert --when you perform an insert operation, the automatic trigger triggers, both for and alter, are executed after the operation, or they can be changed to alter as UpdateStudentSetSsex='female' whereSno=103GoSelect* fromStudentCreate TriggerStudent_delete onStudentinstead of Delete --replace an action with the procedure of a trigger to replace the deleted action, no longer able to delete the student table data as UpdateStudentSetSbirthday='2015-4-29' whereSno= theGoDelete fromStudent--CREATE TRIGGER Trigger name--On table name--(For/alter/instead of) + action (insert/delete/update/)-- as--Stored Procedure Content--Go--For/alter the action before triggering the trigger--instead of direct substitution operation--drop trigger Trigger name Delete trigger--temp table in trigger: deleted,insertedCreate TriggerCourse_delete onCourseinstead of Delete as Select * fromdeletedGoDelete fromCourse--deleted is a temporary table that stores the data you want to delete.Create TriggerCourse_delete onCourseinstead of Delete as Delete fromScorewhereCnoinch(SelectCno fromdeleted)Delete fromCoursewhereCnoinch(SelectCno fromdeleted)Go--back up data to backup table before deleting--transactions: Ensure the complete implementation of the entire process, all without problems, unified submission, once there is a problem back to the original pointbegin Tran --things start--start Write process statement--After you finish writing the statementif @ @ERROR>0 --@ @ERROR The error number in the store statement, no error is 0rollback Tran--rolling back thingsElseCommit Tran--Submit Things--three paradigms of---database design--1. The values in each column are single--2. Meet 1, each table must have a primary key--3. Satisfy 2, the foreign key table only appears in the primary key table in the primary key column, the other columns do not appear. When there are three columns in a table and more of the data is often duplicated, you need to take these columns out to create a separate table--set a primary key, and then only the primary key will be present in the original table.
SQL Server Note 9 (Backup restore trigger transaction three paradigms)