12. Relational Database (1 of 4)Definition Relational Database is database that all data are established many tables to have relationship each other. Each table consists of many columns and many rows that each column is usuallycalled a register,each row is described an attribute. 3
13.
14. Primary key: a collection of one column or many columns inside tables that it is not permit null data and is only one.
15. Foreign key: a collection of one column or many columns inside tables that they are a primary of other tables and their data can be permitted null4
24. Database Management System(2 of 3)Definition Database management system is a software to permit users to create, control and access into database. Database management system has maintained consistency of database during its cycle life. 8
30. Mircosoft SQL server(1 of 3) MS SQL Server is a database management system that it is established and developed by Microsoft based on Transact-SQL method in order to exchange data between Client and MS SQL Server. 10
31. Mircosoft SQL server(2 of 3)Adaptation MS SQL Server is optimized in order to run Very Large Database Environment (VLDE) even though Tera-Byte, especially for serving user thousands MS SQL Server can collaborate with other servers such as Microsoft Internet Information Server (IIS), Oracle... 11
43. How to create index for each record(2 of 2) Syntax: CREATE [CLUSTERED | NONCLUSTERED] INDEXindex_name ON table_name(column_name [, column_name]...) For example for creating non-clustered index on MADV of NHANVIEN columns: CREATE NONCLUSTERED INDEX idx_nhanvien_madv ONnhanvien(madv) 17
61. SP allows transmission parameters, and may be called by many clients over the network with different parameters. When SP is changed, all clients will automatically receive the new version, because the SP is stored at the Server, not Client.25
62. Stored Procedure, Trigger (2 of 9)Stored Procedure Creating procedure CREATE PROCEDURE procedure_name [;number] [([parameter1] [,parameter2]...[parameter255])] AS sql_statements 26
63. Stored Procedure, Trigger (3 of 9)Stored Procedure For example CREATEPROCEDURE sp_users_insert (@firstname varchar(50), @lastname varchar(50), @birthday date, @groupid int) AS BEGIN ifexists(select groupid from groups where groupid = @groupid) BEGIN insertinto users(firstname, lastname, birthday, groupid)values(@firstname,@lastname,@birthday,@groupid) END END 27
67. Stored Procedure, Trigger (5 of 9)Trigger Syntax: CREATE TRIGGER trigger_name ON table_name | view_name [WITH ENCRYPTION] {FOR | AFTER | INSTEAD OF}{ [INSERT] [,] [UPDATE ] [,] [DELETE] } AS sql_statements 29
68. Stored Procedure, Trigger (6 of 9)Trigger CREATE TRIGGER groups_users_delete on groups fordelete as BEGIN DECLARE @groupid int; Set @groupid=(Select groupid from DELETED); deletefrom users where groupid = @groupid END 30
69. Stored Procedure, Trigger (7 of 9)Function Function is database object similar procedures. However, the difference between procedures and function that function returns to a value via its function name while procedures do not. 31
70. Stored Procedure, Trigger (8 of 9)Trigger Syntax CREATE FUNCTION [ schema_name. ] function_name ( [ { @parameter_name [ AS ] [ type_schema_name. ] parameter_data_type [ = default ] [ READONLY ] } [ ,...n ]S ] ) RETURNS return_data_type [ WITH <function_option> [ ,...n ] ] [ AS ] BEGIN function_body RETURN scalar_expression END [ ; ] 32
71. Stored Procedure, Trigger (end)Trigger For example CREATEFUNCTION f_users_tong() RETURNS @bangthongke TABLE (groupid int,groupname varchar(50),tonguser INT) AS BEGIN INSERTINTO @bangthongke SELECT groups.groupid,groups.groupname,COUNT(userid) FROM (groups INNERJOIN users ON groups.groupid = users.groupid) GROUPBY groups.groupid,groups.groupname RETURN END 33
72.
73. View is a virtual screen that it is created as a union of rows and columns by one or many different tables.
78. Supportting tools for MS SQL Server One of the most popular supporting tools for MS SQL sever is SQL Assistant. You can download from link http://www.softpedia.com/progDownload/SoftTree-SQL-Assistant-Download-92428.html 38
79. Demo How to use Diagram Decentralized Backup Restore Function Store Procedure Trigger 39