Interactive SQL (Transact SQL, TSQL)
It is the query language of SQL Server. The following commands are provided:
· Create and database objects.
· Access and modify data.
· Data aggregation (also known as aggregation).
· Implement safety measures.
Database Objects
Database objects are physical objects in the database. These objects have unique names and hold data and data relationship information. SQL Server defines the following objects:
1. Table (table)
A table is a two-dimensional array used to store data. It has rows and columns. Columns are also called table attributes or fields. Each column in the table has a unique name. Each column contains a specific data type. This data type is defined by the data type in the column.
2. View
A view is a virtual table, which only contains part of the table. Unlike a table, the data saved in a view is not physically stored data. It is derived from the table. The derived table is called the base table of the view. The definition of the view is stored in the database.
3. Constraints
Constraints define the integrity and validity of data. Constraints establish rules for the values in a column. In other words, if an end condition is defined on a column, every value inserted into that column needs to pass the constraint check. Constraints are a better choice for ensuring data integrity and validity on triggers and rules. SQL Server Query Optimizer uses constraints to generate low-cost query plans. Constraints are of the following types:
· NOT NULL This constraint requires that there cannot be NULL values in the column.
· CHECK Checks the constraints after specifying the set of values that the column can have. Any data in the column that is outside the definition is invalid data. The set of valid values is called the domain of the column.
· PRIMARY KEY The primary key is a column or column combination, which is used to uniquely identify a row.
· FOREIGN KEY is used to define the parent-child relationship between two tables. If a key is part of the primary key of one table and the primary key of another table, it is called a foreign key. Foreign keywords are used to define the referential integrity of data.
· UNIQUE The unique constraint means that no two rows have the same NON-NULL value in the column. Uniqueness is guaranteed by primary keys, but they do not allow NULL values, and there can be only one key per table.
4. Default value (default)
The default value is the value defined for the column. If the value of a column is not provided when inserting a row, the default value is used for this column. The default value can be one of the following:
·Constant
· Mathematical expression
· Internal function (Built-in function)
5. Rule (rule)
Rule execution has the same function as CHECK constraints. But the difference between rules and constraints is that rules exist as independent objects and can be used in multiple tables, while constraints are stored as part of a table. However, the rules are provided as a backwards compatibility feature and users are advised to use constraints.
6. Triggers and stored procedures
Triggers and stored procedures are a set of TSQL commands, which are stored in the database as an object.
Object naming convention
SQL Server uses a three-part name to identify objects:
The above is the content of Getting Started with SQL Server 7.0 (1). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!