After a long time, I didn't update the 9CBS blog. I have been busy with the exam. I finally took a break in these days and started the knowledge of the self-study database.
Yesterday, I got a few PDF books of SQL Server, put the VS2005, with SQL Server2005EXPRESS version.
Today, I started to create a connection database at MSDN.
Create a database file
(Ms-help: //ms.msdnqtr.v80.chs/ms.msdn.v80.chs.visualstudio.v80.chs/dv_raddata/html/99c2b06f-47aa-414e-8057-a3453712fd23.htm)
Because this drill is an empty database template to create a database, you need a project to create a database.
Create a new Windows project
In Visual Studio, create a new "item" from the File menu. Name the project SampleDatabaseWalkthrough. Select "Windows Application" and click OK. For more information, see
Create a Windows-based application
. The SampleDatabaseWalkThrough project is created and added to the Solution Explorer.
Add new databases to your project
Select "Add New Item" from the Project menu. Select "SQL Database" from the list of available templates. Type SampleDatabase in the Name area. Click Add. Data Source Configuration Wizard will open, but because this is a new database, there is no database object available. Click Finish to create a database and dataset and add them to the project.
Add the table to the database
Open the Server Explorer / "Database Explorer" by selecting Server Explorer / "Database Explorer" from the View menu. Expand the SampleDatabase.mdf node under the Data Connection node. Right click on "Table" and select "Add a new table". "Table Designer" will open. Create columns with the following information:
Column Data Type Allowed Customerid Nchar (5) False (Unchecked) CompanyName NVARCHAR (40) False (Unchecked) ContactName NVARCHAR (30) True (Selected) ContactTitle Nvarchar (30) True (Selected) Address Nvarchar (60) True (Select) City nvarchar (15) TRUE (selected) Region nvarchar (15) True (selected) Postalcode Nvarchar (10) True (selected) Country nvarchar (15) True (selected) Phone nvarchar (24) True (selected) Fax NVARCHAR (24) TRUE (selected)
Select the CustomerID column and then select "Set Primary Key" from the Table Designer menu. Select "Save Table1" from the File menu. Type Customers in the Enter Table Name area. Click OK. Right click on "Table" and select "Add a new table". "Table Designer" will open. Create columns with the following information:
Column Name Data Type Allow Nulls OrderID int False (unchecked) CustomerID nchar (5) True (selected) EmployeeID int True (selected) OrderDate datetime True (selected) RequiredDate datetime True (selected) ShippedDate datetime True (selected) ShipVia int True ( select) Freight money True (selected) ShipName nvarchar (40) True (selected) ShipAddress nvarchar (60) True (selected) ShipCity nvarchar (15) True (selected) ShipRegion nvarchar (15) True (selected) ShipPostalCode nvarchar (10) True (Select) ShipCountry NVARCHAR (15) True Select the "OrderID" column, then select "Set Primary Key" from the Table Designer menu. Select "Save Table2" from the File menu. Type Orders in the Enter Table Name area. Click OK.
Create a relationship between the table created in the previous step
In the Server Explorer / Database Explorer, right-click the "Database Relationship Diagram" node in the "SampleDatabase.mdf" node, and select Add New Relationship. If the dialog opens, you are required to create a necessary database object for the relationship diagram, then click Yes. Add a Customers and Orders tables to a relationship. Close the Add Table dialog. Drag the CustomerID column from the Customers table to the Ordeers table. Verify that the Customers table is "primary key table", and whether the ORDERS table is "foreign key table" and verify that the two tables have selected the CustomerID column. Click "OK" to close the "Table and Column" dialog. Click "OK" to close the Foreign Key relationship dialog and create a relationship. Select "Save Diagram1" from the File menu. Keep the default name and click OK. Click "Yes" in the Save dialog.
Plip the Customers table with data
In Server Explorer / Database Explorer, create a new connection to the Northwind sample database. For more information, see How to: Install the sample database and how: Connect to data in the database. In the Server Explorer / Database Explorer, expand the Northwind database node. Right-click the Northwind Customers table and select "Display Table Data". Select all records and copy them to the clipboard. In Server Explorer / Database Explorer, expand the SampleDatabase.mdf database. Right click on the SampleDatabase.mdf "Customers" table and select "Display Table Data". Paste the Northwind Customers table data from the clipboard.
Fill the Orders table with data
Right-click the Northwind "Orders" table and select "Display Table Data". Select all records and copy them to the clipboard. In Server Explorer / Database Explorer, expand the SampleDatabase.mdf database. Right-click the SampleDatabase.mdf "Orders" table and select "Display Table Data". Paste the Northwind ORDERS table data from the clipboard. Data connected to the database
(Ms-help: //ms.msdnqtr.v80.chs/ms.msdn.v80/ms.visualstudio.v80.chs/dv_raddata/html/02d39aa6-8993-4602-be13-a13536af3d1c.htm)
Create a connection with the Northwind's SQL Server version
On the Data menu, click Show Data Source. In the Data Source window, select Add New Data Source. Click Next. "Next" on the Data Source Configuration Wizard. Select "Database" on the Select Data Source Type page. On the Select Data Connection page, do one of the following:
If the drop-down list contains a data connection to the Northwind sample database, select the connection. Or - Select New Connection to configure a new data connection. For more information, see How to: Creating Connections to the SQL Server Database or how: Create a connection to the Access database. If the database requires a password, select this option to include sensitive data, then click Next. On the "Save Connection String to Application Profile" page, click Next. Expand the "Table" node on the Select Database Objects page. Select "Customers" and "Orders" tables, and then click Finish. "NorthWindDataSet" is added to your project and appears "Customers" and "Orders" tables in the Data Source window.
These are referenced from the MSDN, found that MSDN is really a good thing, but it is very convenient, but so much jump connection, learn the two contents for more than three hours.