« Home « Chủ đề Giáo trình SQL Server 2008

Chủ đề : Giáo trình SQL Server 2008


Có 40+ tài liệu thuộc chủ đề "Giáo trình SQL Server 2008"

Hướng dẫn học Microsoft SQL Server 2008 part 21

tailieu.vn

Nielsen c07.tex V pm Page 162. The script first loads all of the DLLs needed for SMO and the snap-ins (code and commands that extend PowerShell’s capabilities), and then it loads the snap-ins. Once this is done, all of the SQL Server provider functionality is available, and this script can be run against PowerShell 1.0 or PowerShell 2.0 when it...

Hướng dẫn học Microsoft SQL Server 2008 part 22

tailieu.vn

The physical execution plan is very different from the syntactical order, or logical understanding, of the query.. Views, or stored SELECT statements, can be referenced within the FROM clause as if they were tables. Views are discussed in Chapter 14, ‘‘Projecting Data through Views.’’. Distributed data sources pull in data from other SQL Server databases, other SQL Servers, other database...

Hướng dẫn học Microsoft SQL Server 2008 part 23

tailieu.vn

While the two preceding queries are very similar, in the first query the natural order of precedence for Boolean operators caused the AND to be evaluated before the OR . The OR included the Air Writers in the results.. The second query used parentheses to explicitly dictate the order of the Boolean operators. Select...where. Surprisingly, using the WHERE clause in...

Hướng dẫn học Microsoft SQL Server 2008 part 24

tailieu.vn

Whereas the first query returned 16 rows, the DISTINCT predicate in the second query eliminated the duplicate rows and returned only five unique rows.. SQL Server’s DISTINCT is different from MS Access’ distinctrow , which eliminates dupli- cates based on data in the source table(s), not duplicates in the result set of the query.. Of course, using DISTINCT is based...

Hướng dẫn học Microsoft SQL Server 2008 part 25

tailieu.vn

SQL Server’s CASE expression is a flexible and excellent means of building dynamic expressions.. If you’re a programmer, no doubt you use the case command in other languages. It’s not used for programmatic flow of control, but rather to logically determine the value of an expression based on a condition.. W hen programmers write procedural code, it’s often because part...

Hướng dẫn học Microsoft SQL Server 2008 part 26

tailieu.vn

The following example retrieves the day of the year and the day of the week as integers:. The following query calculates the number of years and days that my wife, Melissa, and I have been married:. The following query is based on the Family sample database and calculates the mother’s age at the birth of each child, using the DateDiff()...

Hướng dẫn học Microsoft SQL Server 2008 part 27

tailieu.vn

The advantage of the DIFFERENCE() function is that it broadens the search beyond the first letters.. Data-Type Conversion Functions. Converting data from one data type to another data type is often handled automatically by SQL Server.. CAST(Input as data type. The ANSI standard SQL means of converting from one data type to another. Even when the conversion can be performed...

Hướng dẫn học Microsoft SQL Server 2008 part 28

tailieu.vn

FIGURE 10-4. Building an inner join within Management Studio’s Query Designer. Typically, a primary key value from one table is being matched with a foreign key value from the secondary table. Whenever a row from the first table matches a row from the second table, the two rows are merged into a new row containing data from both tables.. The...

Hướng dẫn học Microsoft SQL Server 2008 part 29

tailieu.vn

INSERT dbo.One(OnePK, Thing1) VALUES (2, ‘New Thing’);. INSERT dbo.One(OnePK, Thing1) VALUES (3, ‘Red Thing’);. INSERT dbo.One(OnePK, Thing1) VALUES (4, ‘Blue Thing’);. INSERT dbo.Two(TwoPK, OnePK, Thing2) VALUES(1,0, ‘Plane’);. INSERT dbo.Two(TwoPK, OnePK, Thing2) VALUES(2,2, ‘Train’);. INSERT dbo.Two(TwoPK, OnePK, Thing2) VALUES(3,3, ‘Car’);. INSERT dbo.Two(TwoPK, OnePK, Thing2) VALUES(4,NULL, ‘Cycle’);. FIGURE 10-9. Red Thing New Thing Blue Thing. An inner join between table One and...

Hướng dẫn học Microsoft SQL Server 2008 part 30

tailieu.vn

To see if the theory will fly in a real-world scenario from the OBXKites sample database, the following code is a set difference query that locates all contacts who have not yet placed an order. The Contact table is the divisor and the set difference query removes the contacts with orders (the dividend). The WHERE condition restricts the result set...

Hướng dẫn học Microsoft SQL Server 2008 part 31

tailieu.vn

Significant recent improvements include the following:. With SQL Server 2008, Microsoft adds row constructors that can be used in the subquery to provide hard-coded values to the query.. Simple subqueries are executed in the following order:. The results are passed to the outer query.. The outer query is executed once.. The most basic simple subquery returns a single (scalar) value,...

Hướng dẫn học Microsoft SQL Server 2008 part 32

tailieu.vn

SELECT P.Code, P.ProductName, Sales.QuantitySold FROM dbo.Product AS P. JOIN (SELECT ProductID, SUM(Quantity) AS QuantitySold FROM dbo.OrderDetail. GROUP BY ProductID) AS Sales ON P.ProductID = Sales.ProductID ORDER BY P.Code;. If you use SQL Server Management Studio’s Query Designer, a derived table may be added to the query.. from the Family sample database:. SELECT p.PersonID, p.FirstName, p.LastName, c.Children FROM dbo.Person AS p....

Hướng dẫn học Microsoft SQL Server 2008 part 33

tailieu.vn

relational division query would list only those students who passed the required courses and no others.. A relational division with a remainder, also called an approximate divide, would list all the students who passed the required courses and include students who passed any additional courses. Relational division is more complex than a join. Relational division finds exact matches between two...

Hướng dẫn học Microsoft SQL Server 2008 part 34

tailieu.vn

Because SQL is now returning information from a set, rather than building a record set of rows, as soon as a query includes an aggregate function, every column (in the column list, in the expression, or in the ORDER BY ) must participate in an aggregate function. Because aggregate functions are expressions, the result will have a null column name....

Hướng dẫn học Microsoft SQL Server 2008 part 35

tailieu.vn

The GROUP BY ALL includes the fourth quarter because there is data for the fourth quarter for 2008:. FROM RawData. GROUP BY ALL DATEPART(qq, SalesDate);. 4 0 NULL NULL. The real problem with the GROUP BY ALL solution is that it’s dependent on data being present in the table, but outside the current Where clause filter. A better solution to...

Hướng dẫn học Microsoft SQL Server 2008 part 36

tailieu.vn

The CASE expression method’s query execution plan is identical to the plan generated by the PIVOT method:. GROUP BY RollUp (Category). ORDER BY Coalesce(Category, ‘ZZZZ’) Result:. however, in both the PIVOT method and the CASE expression method, the crosstab columns ( region in this example) must be hard-coded in the SQL statement.. While it could be done with a cursor,...

Hướng dẫn học Microsoft SQL Server 2008 part 37

tailieu.vn

Ranking Functions. that’s where the ranking functions come into play:. row_number. dense_rank. Just to be explicit, the ranking functions all require the windowing function.. All the normal aggregate functions — SUM. Row number() function. The ROW_NUMBER() function generates an on-the-fly auto-incrementing integer according to the sort order of the OVER() clause. The row number function simply numbers the rows in...

Hướng dẫn học Microsoft SQL Server 2008 part 38

tailieu.vn

Creating views using the Query Designer. Because a view is nothing more than a saved SQL SELECT statement, the creation of a view begins with a working SELECT statement. The New View command in the context menu launches the Query Designer in a mode that creates views, as shown in Figure 14-1.. The View Designer mode functions within Management Studio’s...

Hướng dẫn học Microsoft SQL Server 2008 part 39

tailieu.vn

To understand the need for the WITH CHECK OPTION , it’s important to first understand how views function without the CHECK OPTION . CREATE VIEW dbo.vCapeHatterasTour AS. SELECT TourName, BaseCampID FROM dbo.Tour. SELECT TourName, BaseCampID FROM dbo.vCapeHatterasTour;. If the Ashville base camp adds a Blue Ridge Parkway Hike tour and inserts it through the view without the CHECK OPTION ,...

Hướng dẫn học Microsoft SQL Server 2008 part 40

tailieu.vn

When the data to be inserted, usually in the form of variables sent from the user interface, is known, inserting using the INSERT. Typically, to reference values from a data source, the INSERT. VALUES can include a scalar subquery as one of the values.. Inserting a result set from select. Data may be moved and massaged from one result set...