Danh mục

Define Tables and Fields

Số trang: 5      Loại file: pdf      Dung lượng: 25.93 KB      Lượt xem: 3      Lượt tải: 0    
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

2,2 Xác định cơ sở dữ liệu Bàn Fields A SQL Server không làm nhiều tốt trừ khi bạn có bảng trong nó. Hướng dẫn này không chỉ cung cấp cho bạn thông tin về cách để tạo bảng và các lĩnh vực, nhưng cũng dạy bạn làm thế nào để tên họ và những gì để tìm ra cho khi tạo ra chúng
Nội dung trích xuất từ tài liệu:
Define Tables and Fields 2.2 Define Tables and FieldsA SQL Server database doesnt do much good unless you have tables in it. This tutorialnot only gives you information on how to create tables and fields, but also teaches youhow to name them and what to look out for when creating them. Databases by themselvesdont do much for you, but you need to be able to store data in them at the very least. Todo this, you need to be able to create tables, which are made up of fields. How do you goabout defining tables and fields in VS .NET?TechniqueUsing the Server Explorer and accessing the Table designer, you are going to create atable called tblCustomers in the database that you created in the previous How-To. Youwill then add columns to the database that will store various pieces of information havingto do with individual customers.Last, you will create another table called tblPhones and also create the necessary columnsthat will contain information about phone information for your customers.StepsAfter Visual Studio .NET is opened, expand the Server Explorer and locate your newdatabase called Chapter2, created in How-To 2.1. Click on the plus sign by the databasenames so that the database object categories are listed. 1. Right-click on the Tables node under the Chapter2 database and choose New Table. You will then be presented with the Table Designer. Now you are ready to add the columns. 2. To add a column, you need to set four immediate properties: o Column Name. This is the name of the column. Dont use spaces or special characters, but do use proper case, and make sure that the name you give the column makes sense for what it contains. For instance, if the column is for the last name of a customer, put LastName for the Name property of the column. o Data Type. Depending on the type of data that will be entered into the column, this will be one of the many valid data types for SQL Server, shown here in Table 2.1. Table 2.1. SQL Server Data Types Data Type Description bigint Integer (whole number) data from -263 (- 9,223,372,036,854,775,808) through 263\up6 - 1\up6 (9,223,372,036,854,775,807).int Integer (whole number) data from -2^31 (- 2,147,483,648) through 231 - 1 (2,147,483,647).smallint Integer data from 215 (-32,768) through 215 - 1 (32,767).tinyint Integer data from 0 through 255.bit Integer data with either a 1 or 0 value.decimal Fixed precision and scale numeric data from -1038 + 1 through 1038 - 1.numeric Functionally equivalent to decimal.money Monetary data values from -263 (- 922,337,203,685,477.5808) through 263 - 1 (+922,337,203,685,477.5807), with accuracy to a ten- thousandth of a monetary unit.smallmoney Monetary data values from -214,748.3648 through +214,748.3647, with accuracy to a ten-thousandth of a monetary unit.float Floating precision number data from -1.79E + 308 through 1.79E + 308.real Floating precision number data from -3.40E + 38 through 3.40E + 38.datetime Date and time data from January 1, 1753, through December 31, 9999, with an accuracy of three- hundredths of a second, or 3.33 milliseconds.smalldatetime Date and time data from January 1, 1900, through June 6, 2079, with an accuracy of one minute.char Fixed-length non-Unicode character data with a maximum length of 8,000 characters.varchar Variable-length non-Unicode data with a maximum length of 8,000 characters.text Variable-length non-Unicode data with a maximum length of 231 - 1 (2,147,483,647) characters.nchar Fixed-length Unicode data with a maximum length of 4,000 characters.nvarchar Variable-length Unicode data with a maximum length of 4,000 characters.ntext Variable-length Unicode data with a maximum length of 230 - 1 (1,073,741,823) characters.binary Fixed-length binary data with a maximum length of 8,000 bytes.Varbinary Variable-length binary data with a maximum length of 8,000 bytes.image Variable-length binary data with a maximum length of 231 - 1 (2,147,483,647) bytes.cursor A reference to a cursor.sql_variant A data type that stores values of various SQL Server- supported data types, except text, ntext, timestamp, and sql_variant.table A special data type that stores a result set for later processing.timestamp A database-wide unique number that is updated every time a row is updated.uniqueidentifier A globally unique identifier (GUID). o Tip Unicode is a character-encoding standard that uses 16-bit code values. This standard is used worldwide to represent all the characters that are used in modern computing. Traditional character sets are the previous character- encoding standards-such as the Windows ANSI character set-that use 8-bit code values or combinations of 8-bit values to represent the characters used in a specific language or geographical region. It is recommended that you use Unicode data types-nchar, nvarchar, and ntext-rather than their non-Unicode counterparts. Also, use the varian ...

Tài liệu được xem nhiều: