PartOne Flashcards

2
Q

<span><span>What does SELECT INTO do?</span></span>

A

Run the query. Create the target table. Insert the result of the query into the target table. All data type will be copied except constraints, triggers and indexes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which is not allowed to specify the target column in an insert stmt?

  • default constraint
  • not null
  • identity
A

Identity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is CROSS JOIN?

A

It performs cartesian product of the 2 input table.m rows in T1. n rows in T2. Cross join will produce m x n rows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Left join / Right join

A

ON and WHERE works differently.The preserved side will return all rows regardless.The ON side just matches rows from the unpreserved side to the preserved side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

INLINE table function

A

The function returns a table.Different from VIEW, it accepts parameters.

<span><strong>CREATE FUNCTION</strong> dbo.authors<br></br> ( @au_lname VARCHAR(40) )<br></br> <strong>RETURNS TABLE</strong><br></br> <strong>RETURN</strong><br></br> <strong>SELECT</strong> au_id, au_fname, au_lname, city, state<br></br> <strong>FROM </strong>authors<br></br> <strong>WHERE </strong>au_lname = @au_lname</span>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is CROSS APPLY?

A

Similar to inner join.Does not return left side if table expression returns a empty set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When a primary key or unique constraint is defined, SQL Server create ______ automatically.

A

Unique index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s the precedence?EXCEPT UNION INTERSECT

A

INTERSECT precedes UNION & EXCEPTUNION & EXCEPT are equal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Window functions

A

OVER ([PARTITION BY clause][ORDER BY clause][ROW or RANGE clause] )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Derived table

A

SELECT FROM(Select from where…) as d1 WHERE…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe INDEXED VIEW

A

An unique clustered index is created on the view and the actual result of the view query are stored on disk

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

VIEW WITH SCHEMABINDING

A

Guarantees the underlying table structures cannot be altered w/o dropping the view.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

VIEW WITH ENCRYPTION

A

Make it difficult to discover the SELECT text of the view

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

VIEW WITH VIEW_METADATA

A

Return metadata instead of the base table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

VIEW WITH CHECK OPTION

A

Prevent any updates thru the view that would cause some rows to get values no longer satisfying a where clause of the view

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the VIEW restrictions?

A
  • No order by
  • Does not accept parameters
  • Cannot create tables, permanent or temp
  • Can only reference permanent table. No temp tables.
18
Q

What is SYNONYM

A

Synonyms are names stored in a database that can be used as substitutes for other object names

19
Q

How to move table from one schema to another

A

ALTER SCHEMA TRANSFER

20
Q

ALTER TABLE cannot…

A
  1. Change column name
  2. Add or remove identity
21
Q

DENSE_RANK ( ) OVER ( [] < order_by_clause > )

A

If two or more rows tie for a rank in the same partition, each tied rows receives the same rank. No gaps and always have consecutive ranks.

22
Q

The WHERE clause returns cases where the predicate evaluates to _ and _ the rest. No false or NULL.

A
  • TRUE
  • Discards
23
Q

SARG - search argument

A

Try not to include a field inside a function in the WHERE clause.

Bad - WHERE Year(myDate) = 2008.

Good - WHERE myDate >= ‘01-01-2008’ AND myDate < ‘01-01-2009’ instead.

24
Q

How to show tiebreakers with TOP

A

SELECT TOP(n) WITH TIES

25
Q

OFFSET-FETCH

A

OFFSET - skip m rows FETCH NEXT n ROWS ONLY

26
Q

T-SQL logical order

A

FROM,

WHERE,

GROUP BY,

HAVING,

SELECT,

ORDER BY

27
Q

OPENDATASOURCE

A

Provides ad hoc connection info as part of a 4-part object name, without using a linked server name.

28
Q

T-SQL logical order

A

FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY

29
Q

OFFSET-FETCH

A
  • OFFSET - skip m rows
  • FETCH NEXT n ROWS ONLY
30
Q

Window functions

A

OVER ( [PARTITION BY clause] [ORDER BY clause] [ROW or RANGE clause] )

31
Q

How to move table from one schema to another?

A

ALTER SCHEMA TRANSFER

32
Q

What is SYNONYM

A

Synonyms are names stored in a database that can be used as substitutes for other object names

33
Q

TRUNCATE resets _____ while DELETE don’t.

A

IDENTITY to the initial seed

34
Q

What is distributed transaction

A

Transaction that span more than one server, by using a linked server.

35
Q

__ Sales.Myorders AS TGT

<span>__Sales.Orders AS SRC ON TGT.orderid = SRC.orderid</span>

__( TGT.Custid <> SRC.Custid OR TGT.Empid <> SRC.Empid OR TGT.orderdate <> SRC.orderDate )

__SET TGT.Custid = SRC.Custid, TGT.Empid = SRC.Empid, TGT.orderdate = SRC.orderdate

__(SRC.orderid, SRC.Custid, SRC.empid, SRC.orderdate)

__ THEN DELETE;

A
  1. MERGE INTO
  2. USING
  3. WHEN MATCHED AND
  4. THEN UPDATE
  5. WHEN NOT MATCHED THEN INSERT VALUES
  6. WHEN NOT MATCHED BY SOURCE
36
Q

How to get next value of a Sequence object

A

NEXT VALUE FOR

37
Q

What is the three-valued logic?

A
  • True
  • False
  • Unknown
38
Q

col1 LIKE ‘!_%’ ESCAPE ‘!’

A

Look for value starting with an underscore. ‘!’ is the designated escape character.

39
Q

RANK

A

The RANK function does not always return consecutive integers.