SQL Server - Bài
T-SQL for Data ManipulationVu Tuyet Trinhtrinhvt-fit@mail.hut.edu.vnHanoi University of Technology1 MicrosoftMicrosoftOverview of Transact-SQLBased on AINSI SQL 92 standardComposing of three categoriesData Manipulation Language (DML)Data Definition Language (DDL)Data Control Language (DCL) Having some Microsoft specific extensionsBeyond relational data.net framework integration MicrosoftMicrosoftOutlineSelecting Data from Existing TablesInserting Data Updating DataDeleting DataFulltext Serach MicrosoftMicrosoftSelect DataThe simple syntax to select the items from the exit table is:select <the items > from <name of table>where <conditions> MicrosoftMicrosoftSelect DataYou can change the name of the items in the table: MicrosoftMicrosoftSelect DataYou can insert some items as following: MicrosoftMicrosoftSelectExample a function ‘count’ to count the columns of the table: MicrosoftMicrosoftSelect DataYou can use some functions or some operations in the Select Statement: MicrosoftMicrosoftSelect Data MicrosoftMicrosoftSelect Data Maths FunctionsFunctions String Functions The Time functions [...]...Select Data Maths - AVG() - MIN() - MAX() - SUM() - COUNT() - SQUARE() - SQRT() - ROUND() Microsoft String - ASCII() - CHAR() - UPPER() - LOWER() - LEN() - LTRIM() - RTRIM() - LEFT() - RIGHT() Time - GETDATE() DATEPART(YY,g etdate()) DATEDIFF(X,Y,Z) DAY(),MONTH(), YEAR() Select Data Besides, there are some functions to convert the data type: - CAST() - CONVERT() Microsoft Select With... Select-With statement Specifies a temporary named result set, known as a common table expression (CTE) Microsoft Select-Order by - You can arrange the result follow the first letter by using the order by statement: Microsoft Select-multiple tables You can select the items from more than a table as following: With “outer join”: Microsoft Select – multiple tables Inner join: Microsoft Select-multiple... from many tables, and create a new table to store that result: Now, you can refresh the sql folder, and you can see the new table named newtbl as the following: Microsoft Select-multiple tables Microsoft Select-merge A new feature in SQL2 008 is merge statement You can merge 2 or more tables: Microsoft Select-Group by Specifies the groups into which output rows are to be placed If aggregate functions... Inner join: Microsoft Select-multiple tables - When you select from more than 1 table, you can use the join… on statement or you can use the cross join statement With the cross join statement, you don’t have to have to relative condition between the tables and the result is all the Objects: Microsoft Select-multiple tables Microsoft Select-multiple tables - You can select from many tables, and create... are not also found on the right query Microsoft Select-Compute by enerates totals that appear as additional summary columns at the end of the result set When used with BY, the COMPUTE clause generates control-breaks and subtotals in the result set You can specify COMPUTE BY and COMPUTE in the same query Microsoft Select-Compute by Microsoft Select-For clause OR clause is used to specify either the BROWSE... group Microsoft Select-Having Specifies a search condition for a group or an aggregate HAVING is typically used in a GROUP BY clause When GROUP BY is not used, HAVING behaves like a WHERE clause Microsoft Microsoft Select-intersect NTERSECT returns any distinct values that are returned by both the query on the left and right sides of the INTERSECT operand Microsoft Select-except EXCEPT returns... Microsoft Select-For clause Microsoft Insert The simple syntax for Insert statement is: INSERT INTO VALUES(a,b,…) Microsoft Insert - You can insert some values into the table, and you have to insert all the value not null, and the primary key: Microsoft Insert Microsoft Insert If you don’t insert all the column not null, the process will terminate Microsoft Insert - You can create . functions MicrosoftMicrosoft- ASCII( )- CHAR( )- UPPER( )- LOWER( )- LEN( )- LTRIM( )- RTRIM( )- LEFT( )- RIGHT( )- AVG( )- MIN( )- MAX( )- SUM( )- COUNT( )- SQUARE( )- SQRT( )- ROUND( )- GETDATE()-DATEPART(YY,getdate() )-. T -SQL for Data ManipulationVu Tuyet Trinhtrinhvt-fit@mail.hut.edu.vnHanoi University of Technology1 MicrosoftMicrosoftOverview of Transact -SQL Based