Home > Database > Mysql Tutorial > Getting Started with SQL Server 7.0 (1)

Getting Started with SQL Server 7.0 (1)

黄舟
Release: 2016-12-24 17:35:36
Original
2252 people have browsed it

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 first two parts can be omitted, The system has a default value. The default value for the database name is the current database, and the default value for the owner name is the database owner (dbo).

Data type
Any object containing data has a data type associated with it. Data types are properties that specify what kind of data an object can contain.
       SQL Server data type
Data type
said
Synonyms

Bit
1 bit, the value is 0 or 1
Int

Integer
4 bytes, the value is -2^31~2^31-1


Smallint
2 bytes, the value is -2^15~2^15-1


Tinyint
1 byte, the value is 0~255


Decimal (p,s)
Number data, fixed precision is P , the width is S
Numeric

Money
8 bytes, the currency type is stored, the value is -2^63~2^63-1


Small money
4 bytes, the currency type is stored, the value is -214748.3648~+ 214748.3647 Approximate numerical data type


Float (n)
N is between 1~24, 4 bytes, 7-bit precision
N=1~7 is real


N is between 25~53, 8 bytes , 15-digit precision
=8~15 is float

Datetime
8 bytes, describing the date and time of a certain day, the accuracy of the value is 1/300 second


Smalldatetime
4 bytes, describing the date of a certain day and time, precision is minutes


Cursor
Reference to cursor


Timestamp
8 bytes, stored in the database unique data


Uniqueidentifier
16 bytes, stored globally unique identifier (GUID)


Char (n)
Fixed length of non-unicode string, n=1~8000
Character (n)

Varchar (n)
Variable length, non-unicode string n=1~8000
Char varying(n)

Text
Variable-length non-unicode data in the server code page. The maximum length is 231-1 characters


Nchar
Fixed length unicode string n=1~4000
National character (n),
National char(n)

Nvarchar
Fixed length unicode string n=1~4000
National character varying(n)

Ntext
Variable length unicode data, the maximum length is 230-1 characters
National text

Binary (n)
Fixed length binary data, n is between 1~8000, storage space is n+4 bytes


Varbinary (n)
Variable length binary data, n=1~8000
Binary varying (n)

Tmage
Variable length binary data, size is 0~231-1


Note:
1) For numeric data types, the width (scale) refers to the number of digits stored after the decimal point, and precision (precision) refers to all the number of digits that can be stored including the decimal point.
2) The storage width of money and small money is 4.
3) The timestamp column value is automatically updated by the system when each row is updated. The timestamp column cannot be a keyword or part of a keyword.
4) The unique identification data type cannot use arithmetic operators (such as +, -, etc.). This data type can only use equality comparison operations. Unicode is a standard for storing data consistently across all character sets. It uses twice the storage space of non-Unicode data storage.

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)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template