Basic Database "table"
What is the database? As the name implies, it is the place where data is stored, but where is the data stored in the database? It is stored in tables. A table is a tool used to store data in a database. The tables in the database are similar to the tables in our real world.RowAnd ColumnColumn.
A column is composed of similar information. It is an attribute or feature, also known as a field. A row contains information of several columns and is also called a record. It indicates a combination of information, it is used to describe an object as a whole. For example, a student information table contains names, gender, birthdate, nationality, and so on. The information is combined to describe the student.
When designing a database table, you must determine what table is needed according to the requirements of the database logical structure design.5The data in each table, the Data Types contained in the table, the Data Types of each column in the table, the column width, the allowed null values, and the required indexes, which columns are primary keys and Foreign keys. The table is designed in more detail during table creation and operation.
Data Integrity in database tables is achieved by using column data types, constraints, default designs or rules,SQL ServerProvides multiple mechanisms to enforce data integrity in columns. The most effective way to create a table is to define the information required in the table at one time, including data constraints and additional components.
With the basic concept of a table, the next step is to create a table. In fact, database operations are generally divided into two categories. One is to use the Enterprise Manager, and the other is to useT-SQLLanguage. Therefore, two methods are generally used to create a table. As follows:
Create with Enterprise Manager
UseT-SQLLanguage Creation
Creat table
[Database-name. [ower]. | ower.] Table-name
({<Colum-definition> | column-name as copputed-column-expressionl | <Table-constraint>} [,... n])
[On {filegroup | default}]
[Textimage_on {filegroup | default}]
<Column_definition >::={ column_name data_type}
[[Default constant_oxpression] | [identity [seed, increment]
[<Column_constraint>] [... n]
Database_name:Used to specify the name for creating a database in it
Ower: Specifies the username of the new table owner.
Table_name: Used to specify the name of the newly created table
Column_nameUsed to specify the name of the column in the new table
Computed_column_expressionColumn value expression used to specify the calculated Column
On {filegroup |Dedault}: Specifies the name of the file group for storing tables.
Textimage_onUsed to specifyText ntextAndImageFile Group for column data storage
Data_typeSpecifies the Data Type of a column.
DedaultSpecifies the Data Type of a column.
Constant_expressionConstant expression used to specify the default value of a column
IdeentityUsed to specify the column ID column
SeedUsed to specify the initial value of the ID column
IncrementUsed to specify the increment value of the ID column
Column_constraint_constraintUsed to specify column constraints and table constraints.
Example: CreateEmployee info table
Createtable employee
(Number int not null,
Name varchar (20) not null,
Sex char (2) null,
Birthday datetime null,
Hire_date datetime not null
Default (getdate ())
Professional_title varchar (10)
Null,
Salary money null,
Memo ntext null
)
Similarly, the addition, deletion, modification, and query of tables are generally two types of methods, that is, using the Enterprise Manager andT_ SQLLanguage
The "table" is simple to say, but it may be different from what you think. Because the database is studying the table, if the table is very thorough, then there is no problem with the database.