Hey, today we end the basic C # Learning, the beginning of the second stage of learning, is the study of SQL Server. Today is a Monday, is a new beginning, it feels like we are all a week of calculation, and not every day to this point is to say goodbye to today's life, so the new week, new start, new mood, new learning, New harvest. Here's a summary of what we learned today about SQL Server, hey.
I. The process of entering the environment
When we install the environment of the database system, we can create a shortcut for ourselves, hey, we are using 2008 version of the, double-click Open the database system shortcuts, the process is as follows.
In the figure above, the server name is the name of the database server to be logged in, and we learn it on our local computer, so here we can use a point to express, but we in the following authentication method, there are two ways to enter the database system, one we can choose to use Windows Authentication, Click to log in, or we use SQL Server Authentication login, and here the login name and password is we install the database system time set the user name and password, this is also our work often used, because at work we will choose the database server will not be in the machine, So at this point you need to select the name of the server, as well as his login name and password, this time if we forget to use SQL Server Authentication login and password, then we can choose to login with Windows authentication, and then modify the login name and password, the following summary under the change password:
Through the above operation, we can use up the database more convenient, hey.
two. Create a database
Above can see that we enter the database system will see the above, after the database opened there will be a system to us to create a good system database and system tables, and then we can build a new database, click on the database to the right of the new database, select will appear above the interface, and then fill in the database name, Select the path where the database will be stored, and click OK.
Or we can use the database statement to create the system after opening the data, click on the top left of the new query to create the database statement, that is, the following code:
create Database CLA on Primary (name=CLA, filename='D:\sql\cla.mdf', --The location of the database to be created MDF storage size=4MB,--database is created with an initial knowledge size of 4MB maxsize=10MB,--the database is created with a maximum MDF capacity of 10MB filegrowth=1MB--The capacity of the database MDF that is created increases by 1MB per time on the basis of the default size) log on (name=Claa, filename='D:\sql\claa.ldf', --As above , create a log file for the database size=4MB, MaxSize=10MB, FileGrowth=Ten%----The capacity of the database LDF created on the basis of the default size increases his 10% each time )
When we just execute the CREATE database CLA code, the databases we create will be stored in the system path by default, and this path is where we install the database, and we use it more cumbersome, so we can create our store path.
Three. Operation of the database
Execute data --database rename
Use data- - Select this database drop db Data --delete this database
using code we can manipulate the database, rename and delete the created database, then the following summary of the manual operation of the database, hey.
Rename : We select the database we want to rename, click on the right button to rename the option, select Rename.
Select database:
Delete database: Select the database you want to delete, right click, select Task, then select Detach in task to delete database; Here we often get the case of database deletion error, then we go to the service and let its SQL Server MSC stop service to delete the database.
It is also important to note that if we have created a good database, then we can also select the database, and then click the right mouse button, then there is an additional, select Attach, and then select the location of the database, you can add the database we created.
Four. Creation of data Tables
Above we have created a database, and then we will create a data table in this database, as follows:
User Database Lala
Go
CREATE TABLE Class - creates a data table, which is not case- sensitive here(int identity (1,1) Primary key, --Create a Data table field field type identity (1,1) is identified, the identity seed is 1, the identity increment is 1, which starts at 1, and grows to 1 each time. CName varchar (null, -- field varchar typically used for string types
Cdescription text) --Typically a literal type
User Database Buiness
Go
CREATE TABLE Student (sIdintIdentity1,1) primary key,--primary key to set the primary key SclassidintNotNULL,--not Null is a non-null constraint sName varchar ( -) notNULL, SAgeintNotNULL,--int for shaping SNo numeric ( -,0), SSex nchar (1), Sbirthday datetime)
CREATE TABLE warehouse (warehouse IDintIdentity1,1) primary key, warehouse number varchar ( -) Unique, city varchar ( -)default 'Beijing', AreaintCheck (Area > -and Area < -)default +, Creation time datetime) CREATE TABLE employee (Employee IDintIdentity (1,1) primary key, employee number varchar ( -) Unique, warehouse number varchar ( -) references warehouse (warehouse number), name varchar ( -), sex nchar (1) Check (gender ='male'or sex ='female')default 'female', WagesintCheck (Salary ='1800'and wages ='20000') CREATE TABLE vendor (Vendor IDintIdentity1,1) primary key, vendor number varchar ( -) Unique, supplier name varchar ( -), City varchar ( -), contact varchar ( -), e-mail varchar ( -)default '***@**.com') CREATE table order (Order IDintIdentity1,1) primary key, vendor number varchar ( -) References supplier (supplier number), staff number varchar ( -) References employee (employee number), order number varchar ( -), Order date datetime, amountint)
Above we used code to create a data table for the Lala database and the buiness database, let's say manually creating the data table:
We re-create a new database datd, and then select the database, click the Select its submenu "Table", select the table right mouse button, select New table.
Here we just need to fill in the column name and select the data type, whether it is empty, you can choose other constraints below, such as whether the identification and so on. Then refresh the table, select the table we just created, click the right mouse button and select "Edit Top 200 lines" to edit the contents of the table.
Hey, today is a simple study of SQL Server, in the study of this is still just beginning, I still want to practice more practice Operation statement, although before study, but are fur, study on serve something just attitude, can't too believe oneself, OK, today's summary is written here; Suddenly think of the weather forecast, Henan Zhengzhou, Friends of the attention, there is rain and snow tomorrow,-1 degrees to 6 degrees, travel remember to take umbrella, and then by the way to Beijing's friends say, Beijing tomorrow cloudy, but good cold, 零下3度 to 3 degrees, hey ...
Farewell to C #, into the next stage of learning