The definition, deletion of schema and the definition, modification, and deletion of tables in SQL server

(1) Mode definition and deletion
First create a user, and then create a mode for the
user. User creation —> select the database used —> security —> right-click the user —> new user,
select the user type without login in the general column Name the SQL user, and then customize the user name, the framework uses the default.
Insert picture description hereCreated for the user mode
over the New Query select the corresponding database (database selected must be careful which one), enter the code
Insert picture description here
to test the code again run
Insert picture description herecan re-architecture (SQL schema refers mode) to find patterns created
Insert picture description here
also You can use the following code to create a schema, and you can also define a table
Insert picture description here

Delete mode
In SQL, there is no distinction between CASCADE and RESTRICT, only this keyword can be recognized, but the deletion in SQL is deleted by default with RESTRICT
Insert picture description here(2) The definition, deletion and modification of the
basic table Define the basic table: create a student Table Student
Insert picture description here
Create a course table Course
Insert picture description here
Create a student selection table
Insert picture description here
Modify the basic table
Three basic tables have been created, now modify
Insert picture description here
the table Add "Enrollment Time" to the student table
Insert picture description hereInsert picture description here
Change the data type of the data in the table Add
Insert picture description here
the constraint condition of the course name to
Insert picture description here
delete Basic table
The deletion of the table in SQL is the same as the deletion of the schema. The default is RESTRICT, but only these two keywords can be recognized, so the selected table is directly deleted, and the table cannot be referenced by the constraints of other tables.
Insert picture description here
Because of the elective course Table SC has to constrain the referenced student table Student, so if you want to delete Student, you have to delete SC together.
Insert picture description here
Summary:
There is no difference in most operations in SQL. Only the deletion of schema and table needs to be noted. In SQL, CASCADE and RESTRICT cannot be recognized. , But at the same time SQL is deleted by default as RESTRICT. At the same time, it should be noted that the code to create the class can only be run once, and an error will be reported if it is run multiple times.

Guess you like

Origin blog.csdn.net/MHCddt/article/details/115216508