Database Application diagram 1
I have been exposed to a large number of database contents in my previous years. because the company has a large number of software users, it needs to use databases to manage users well. in today's fierce business competition, whether an enterprise can have its own database system is highly managed. small enterprises also need databases as their own support. in general, it is very convenient to use the database and get twice the result with half the effort.
Let's start with the most basic operations.
Enter:Services. MSC
I. Start the service
2. Two authentication methods for database Login
Another authentication method is SQL Server Authentication.
Steps not available for SA:
1. Log On with windows, right-click "instance", "properties", and "security", and set "server authentication method"
For "SQL Server and Windows", click OK. "Restart the service ".
2. Enable the SA account. After connecting to the database with windows, click "security" → "Login Name" → right-click "sa" attribute,
→ Status → enable. After enabling, find the "general" tab and modify the SA password.
Instance
Enable SA account
Create a database:
3. Create a database
How to Create a table?
4. Create a table
5. How to Set automatic numbers
6. Modify the created table
7. add data to the table
8. Common Data Types in Databases
Lists the data types in common databases.
The following is a brief introduction.
Sometimes the image information is stored in the database, and the binary image type is used in this case.
Char (10) cannot store more, for example, 11, but it is OK if it is missing. The occupied space is fixed.
We recommend that you use nchar (10) for gender storage.
Char and nchar all with no VaR in front indicate fixed length.
Varchar and nvarchar indicate the variable length and the variable length.
Varchar (10); 2. during actual storage, the length is calculated dynamically based on the actual data,
If the length exceeds the pre-declared length, an error is returned. If the length is not enough, re-calculate the value based on the actual length.
Generally, a variable length is used for an address.
Nchar (10)
Differences between char (10) and nchar (10:
Char (10) 'aaaaaaaaaaa', 'Look for look' occupies 10 bytes
Nchar (10) 'aaaaaaaaaaa', 'Look for it, look for it ', accounting for 20 bytes
When will n be used? The system uses Chinese information and char.
However, if you want to execute the command in an English operating system, we recommend that you use the command with N.
Their maximum value: varchar (8000)
Char (8000)
Nvarchar (4000)
Nchar (4000)
Varchar (10)
Nvarchar (10)
Varchar (max)Article.
Nvarchar (max)
This is not recommended after sql2005.
Text
Ntext
Database separation and Addition
9. Separation
10. Separation 2
11. Additional
12. Attach 2
The automatic number will always go forward and never go back.
The following describes how to useCodeCreate a database
13. Create a database
14. database creation code
Create a table:
15. Create a table in the database
16. Go statements
If I want to copy my database scripts to my colleagues, but I am using sql2005 and sql2008, I cannot use separation, attached. take the following steps:
17. Step 1 of script generation
Select next
Select: compile all scripts for the entire database.
18. Step 2
Of course, there are some items that we can choose from. In this case, we will not describe them one by one.
Some minor problems may occur when attaching this part. Can you ask me if you have any questions?
CTRL + K + C comments;
CTRL + K + u uncomment;
The result is an attempt to use Ctrl + R
19. How to view data in a table
The following describes how to insert data.
20. insert data
Excluding the automatic numbers, do not manually insert those columns.
21. insert data not empty
22. Translated
Data must be inserted into columns that cannot be empty. Otherwise, an error is returned.
23. Insert automatic ID
24. Insert multiple rows of data
Pay attention to this writing method. Union will be detailed later.
25. export data from the current table to a new table
26. Create a table with the same structure as the source table but without data
New Content
Add suggestion
27. insert data to an existing table
18th, insert Chinese, add n
The following describes common update Methods:
29. Update the column
Thirty. Update multiple columns of data at the same time
Let's talk about this first.
. Conditional query rows
Limit column and row Query
33. Update the specified row and column at the same time.
Note that you must back up the data before updating the data. Otherwise, it may be troublesome. You can make a backup and restore.
. Both update conditions are met.
Pay attention to the use of the logical operators not and or in the database; Priority: Not and or
35. Add 1 to all ages.
It is better to add 1 to the database or write it as a graph. If this is always the case, you may not be able to use it in another place. Parentheses can change the priority.
The following describes two ways to delete data:
36. Delete the specified data
. Differences between the two deletion statements
The comments in the figure are the differences between them.
The following describes some constraints:
Before creating a constraint, delete all the previous data because the previous data is invalid.
Step 1 of building constraints
. Step 2 of constraints
Forty. Step 3 of constraints
Click: Expression
Input constraints
Click: OK
XI. constraint execution
. Set other constraints
Forty-three constraints: Get the current database time
Other forms except check constraints:
Default constraint:
Forty-four, modify the default value
Unique Constraint
Forty-five, unique constraint, such as the ID card number cannot be the same
Forty-six, fill in the content with the unique constraint
If the number of departments I enter is 30, but the number of departments in the department table is not 30. At this time, I need to set the foreign key.
Foreign key constraints:
47. Create foreign key constraints
Forty-eight foreign key relationship settings
Point: Table and column standards
Set the foreign key table and associated ID of the primary key table.
Click OK to automatically generate the ID and name
Forty-nine, set the primary and Foreign keys
We can clearly see that the primary key is yellow and the foreign key is gray.
Tables that are not referenced by foreign keys can be deleted, but referenced tables cannot be deleted.
Since the establishment of the relationship between the primary and external building will cause a series of troubles, we generally do not build. HoweverProgramTo maintain the external relationship.
50. prelude to deleting the external creation Constraints
51. Delete the primary and external creation constraint 1
Delete external primary key constraint 2-cascade Delete
List of recent articles by the author:
C # basic tutorial (free of charge, the best gift for code lovers. Note: The authors share their carefully organized basic C # tutorials without any commercial purposes. I hope to share my experiences with more code lovers. Please give me more advice !!!) |
Process-oriented, object-oriented, and advanced |
Process-oriented, object-oriented in-depth understanding 1 |
Process-oriented, object-oriented in-depth understanding 2 |
Object-oriented deep understanding 3 |
Winform Basics |
Winform Basics |
Commonly used controls in winform |
Process-oriented |
Comparison of three cycles |
Method (I) in C) |
Our common Array |
Object-oriented |
Thought Change |
C # super-class and easy-to-use classes |
The use of destructor and namespaces in C # |
C # super-class and easy-to-use strings |
How to quickly process strings in C # |
Value Type, reference type, and others |
Arraylist and hashtable |
Arraylist and hashtable |
File Management |
Polymorphism |
Section on other issues in C # |
GDI + |
The GDI + code I have collected over the years |
The GDI + Code 2 I collected over the years |
HTML Overview |
HTML language that you cannot ignore |
You can't ignore HTML 2. |
HTML language 3 that you cannot ignore |