BÀI 2 NGÔN NGỮ T-SQL
Số trang: 40
Loại file: pdf
Dung lượng: 845.49 KB
Lượt xem: 21
Lượt tải: 0
Xem trước 4 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
System-Supplied datatype: Các kiểu dữ liệu cơ bản được hỗ trợ bởi SQL Server.Ví dụ 2: Tạo kiểu dữ liệu tên là zipcode với kiểu dữ liệu cơ bản là char, độ dài tối đa là 10 và chấp nhận giá trị NullEXEC sp_addtype zipcode, char(10), NULLVí dụ 3: Tạo kiểu dữ liệu tên là longstring với kiểu dữ liệu cơ bản là varchar, độ dài tối đa là 63 và chấp nhận giá trị NullUser-defined datatype: Các kiểu dữ liệu của người dùng tự định nghĩa dựa trên các kiểu dữ liệu cơ bản....
Nội dung trích xuất từ tài liệu:
BÀI 2 NGÔN NGỮ T-SQLBÀI 2 NGÔN NGỮ T-SQL 1Nội dung 1. Giới thiệu T-SQL 2. Kiểu dữ liệu 3. Hàm và biểu thức trong T-SQL 4. Tạo Table 5. Sửa cấu trúc Table 2 Giới thiệu T-SQL T-SQL gồm 3 nhóm lệnh: DDL (Data Definition Language): được dùng để tạo và chỉnh sửa cấu trúc CSDL CREATE/ALTER/DROP DATABASE CREATE/ALTER/DROP TABLE DML (Data Manipulation Language): được dùng để nhập liệu, chỉnh sửa hoặc rút trích dữ liệu trong 1 CSDL SELECT INSERT, UPDATE, DELETE, TRUNCATE DCL (Data Control Language): được dùng để quản lý việc truy xuất dữ liệu của SQL server GRANT/REVOKE/ADD COMMIT/ROLLBACK 3System Global VariablesHold information useful to the database user.They are prefixed with the @@ sign. 4System Global Variables(contd.) Variable Return value@@Trancount Number of transactions currently open on the connection@@Servername Name of local servers running SQL Server@@Rowcount Number of rows affected by the latest SQL statement@@Nestlevel Nesting level of the current stored procedure execution@@Language Language being used currently@@Servicename SQL Server service name on the current computer@@Procid ID of the current stored procedure@@Connections Number of connections established with the server since it was started 5 Kiểu dữ liệu – Data type Có 2 nhóm: System-Supplied datatype: Các kiểu dữ liệu cơ bản được hỗ trợ bởi SQL Server. User-defined datatype: Các kiểu dữ liệu của người dùng tự định nghĩa dựa trên các kiểu dữ liệu cơ bản. 6Kiểu dữ liệu - Data Type 7Kiểu dữ liệu - Data Type 8 Kiểu dữ liệu - Data TypeTạo một User-Defined Data Type Dùng thủ tục hệ thống sp_addtype để tạo một user-defined data type.sp_addtype type, system_data_type [,NULL | NOT NULL] Ví dụ 1: Tạo kiểu dữ liệu tên là isbn với kiểu dữ liệu cơ bản là smallint và không chấp nhận giá trị Null EXEC sp_addtype isbn, ‘smallint’, ‘NOT NULL’ 9 Kiểu dữ liệu - Data Type Ví dụ 2: Tạo kiểu dữ liệu tên là zipcode với kiểu dữ liệu cơ bản là char, độ dài tối đa là 10 và chấp nhận giá trị Null EXEC sp_addtype zipcode, char(10), NULL Ví dụ 3: Tạo kiểu dữ liệu tên là longstring với kiểu dữ liệu cơ bản là varchar, độ dài tối đa là 63 và chấp nhận giá trị Null EXEC sp_addtype longstring, varchar(63), NULL 10 Kiểu dữ liệu - Data TypeXem các user-defined data types trong CSDL hiện hành: Dùng thủ tục sp_help hoặc vấn truy trong information_schema.domains Ví dụ: Use SalesDB Sp_help hoặc SELECT domain_name, data_type, character_maximum_length FROM information_schema.domains ORDER BY domain_name 11 Kiểu dữ liệu - Data Type Xoá một User-Defined Data Type: dùng thủ tục hệ thống sp_droptype để xóa một user-defined data type từ bảng systypes. Một user-defined data type không thể xóa được nếu nó được tham chiếu bởi các bảng và những đối tượng khác. Cú pháp: Sp_droptype type Ví dụ: EXEC sp_droptype isbn 12 Kiểu dữ liệu - Data Type Dùng Enterprise Manager để tạo: 13 13 Hàm và biểu thức trong T-SQL Function DescriptionGeneral ISDATE(exp) Returns 1 if exp is a valid dateFunctions ISNULL(exp1,exp2) Returns Null if exp1 is NULL, otherwise exp1 returned ISNUMERIC(exp) Returns 1 if exp is a number type NULLIF(exp1, exp2) Returns NULL if both expressions are equivalent, otherwise returns is exp1String ASCII(char) Returns the ASCII value of aFunctions Character. CHAR(int) Returns the character value for an ASCII integer value. CHARINDEX(string1 Returns the starting position for , string2, start) string1 in strin ...
Nội dung trích xuất từ tài liệu:
BÀI 2 NGÔN NGỮ T-SQLBÀI 2 NGÔN NGỮ T-SQL 1Nội dung 1. Giới thiệu T-SQL 2. Kiểu dữ liệu 3. Hàm và biểu thức trong T-SQL 4. Tạo Table 5. Sửa cấu trúc Table 2 Giới thiệu T-SQL T-SQL gồm 3 nhóm lệnh: DDL (Data Definition Language): được dùng để tạo và chỉnh sửa cấu trúc CSDL CREATE/ALTER/DROP DATABASE CREATE/ALTER/DROP TABLE DML (Data Manipulation Language): được dùng để nhập liệu, chỉnh sửa hoặc rút trích dữ liệu trong 1 CSDL SELECT INSERT, UPDATE, DELETE, TRUNCATE DCL (Data Control Language): được dùng để quản lý việc truy xuất dữ liệu của SQL server GRANT/REVOKE/ADD COMMIT/ROLLBACK 3System Global VariablesHold information useful to the database user.They are prefixed with the @@ sign. 4System Global Variables(contd.) Variable Return value@@Trancount Number of transactions currently open on the connection@@Servername Name of local servers running SQL Server@@Rowcount Number of rows affected by the latest SQL statement@@Nestlevel Nesting level of the current stored procedure execution@@Language Language being used currently@@Servicename SQL Server service name on the current computer@@Procid ID of the current stored procedure@@Connections Number of connections established with the server since it was started 5 Kiểu dữ liệu – Data type Có 2 nhóm: System-Supplied datatype: Các kiểu dữ liệu cơ bản được hỗ trợ bởi SQL Server. User-defined datatype: Các kiểu dữ liệu của người dùng tự định nghĩa dựa trên các kiểu dữ liệu cơ bản. 6Kiểu dữ liệu - Data Type 7Kiểu dữ liệu - Data Type 8 Kiểu dữ liệu - Data TypeTạo một User-Defined Data Type Dùng thủ tục hệ thống sp_addtype để tạo một user-defined data type.sp_addtype type, system_data_type [,NULL | NOT NULL] Ví dụ 1: Tạo kiểu dữ liệu tên là isbn với kiểu dữ liệu cơ bản là smallint và không chấp nhận giá trị Null EXEC sp_addtype isbn, ‘smallint’, ‘NOT NULL’ 9 Kiểu dữ liệu - Data Type Ví dụ 2: Tạo kiểu dữ liệu tên là zipcode với kiểu dữ liệu cơ bản là char, độ dài tối đa là 10 và chấp nhận giá trị Null EXEC sp_addtype zipcode, char(10), NULL Ví dụ 3: Tạo kiểu dữ liệu tên là longstring với kiểu dữ liệu cơ bản là varchar, độ dài tối đa là 63 và chấp nhận giá trị Null EXEC sp_addtype longstring, varchar(63), NULL 10 Kiểu dữ liệu - Data TypeXem các user-defined data types trong CSDL hiện hành: Dùng thủ tục sp_help hoặc vấn truy trong information_schema.domains Ví dụ: Use SalesDB Sp_help hoặc SELECT domain_name, data_type, character_maximum_length FROM information_schema.domains ORDER BY domain_name 11 Kiểu dữ liệu - Data Type Xoá một User-Defined Data Type: dùng thủ tục hệ thống sp_droptype để xóa một user-defined data type từ bảng systypes. Một user-defined data type không thể xóa được nếu nó được tham chiếu bởi các bảng và những đối tượng khác. Cú pháp: Sp_droptype type Ví dụ: EXEC sp_droptype isbn 12 Kiểu dữ liệu - Data Type Dùng Enterprise Manager để tạo: 13 13 Hàm và biểu thức trong T-SQL Function DescriptionGeneral ISDATE(exp) Returns 1 if exp is a valid dateFunctions ISNULL(exp1,exp2) Returns Null if exp1 is NULL, otherwise exp1 returned ISNUMERIC(exp) Returns 1 if exp is a number type NULLIF(exp1, exp2) Returns NULL if both expressions are equivalent, otherwise returns is exp1String ASCII(char) Returns the ASCII value of aFunctions Character. CHAR(int) Returns the character value for an ASCII integer value. CHARINDEX(string1 Returns the starting position for , string2, start) string1 in strin ...
Tìm kiếm theo từ khóa liên quan:
Hệ cơ sở dữ liệu lập trình SQL quản trị dữ liệu bải giảng SQL Server bảo mật dữ liệuTài liệu có liên quan:
-
Đáp án đề thi học kỳ 2 môn cơ sở dữ liệu
3 trang 339 1 0 -
PHÂN TÍCH THIẾT KẾ HỆ THỐNG XÂY DỰNG HỆ THỐNG ĐẶT VÉ TÀU ONLINE
43 trang 307 2 0 -
74 trang 280 4 0
-
Khắc phục lỗi không thể đính kèm dữ liệu trong Gmail
3 trang 224 0 0 -
Một số phương pháp bảo mật dữ liệu và an toàn cho máy chủ
5 trang 220 0 0 -
6 trang 212 0 0
-
Giáo trình Nhập môn Cơ sở dữ liệu - GV. Nguyễn Thế Dũng
280 trang 195 0 0 -
Bài giảng học Lý thuyết tài chính- tiền tệ
54 trang 182 0 0 -
Hướng dẫn tạo file ghost và bung ghost
12 trang 161 0 0 -
Trắc nghiệm và đáp án hệ cơ sở dữ liệu - ĐH Công Nghiệp Tp. Hồ Chí Minh
63 trang 126 0 0