SQL Server Questions

May 28, 2016 | Author: jbk111 | Category: Types, Instruction manuals
Share Embed Donate


Short Description

Sql Server DBA and Developer Interview FAQ...

Description

c      p                   p   p        !  " #     p       " $ R

%&&'!   ()% * 

R R R

%&&+!   ,-.    &+ %&&,!   ,+.   /  %&&&!   0-.   " 1

R R R R R

%&&&!   0-2 34.   4  )---!   )---')! .   " "  5- )--'!   )---,(! .      )--+!   )--+.   67  &- )--+!   )--+81 8  .      

R R

Π         p    )--+81 8   "    " p    )--+          )--+.""   p     )--+81 8  $ %9" p    )--+81 8      )9" :    "    .  7  1"  ; 8  ' 7    "        "$ Name: dotnetfx.exe Location: C:\temp Size: 23,510,720 bytes *ersion: 2.0.50727.42 (=  8  81   +  7"     $$> > 1 1  " p *8 :  7)-   ":"     ""     c  #() (  #$"% &$*$ 4   1             " *8 :  7)-6      .         "  #  *8 :  7)-   1       $ CPU usage: 00% Memory usage: 2,704K Launching method: System Service

irectory: C:\WIN ÑWS\Microsoft.NET\‰ramework\v2.0.50727\ ‰ile name: mscorsvw.exe

escription: .NET Runtime Ñptimization Service Size: 66,240 bytes

ate: ‰riday, September 23, 2005, 7:28:56 AM *ersion: 2.0.50727.42 Company name: Microsoft System essential: No *irus/Spyware/Adware: No Œ      2 "      )--+81 8  .""      $ %  7 8J. "  72C " =  p      F   . 1   F  9. "! 7F . "  7*  F  " F   1 p  " 4  =  1.   . "  7=           "  !   8     p     .   1  "       A   ""    :2p *2    "    "    "   "    8:3F A3 338   p "        . "          "      "      "                !     CREATE LÑrIN [computer_name\Mary] ‰RÑM WIN ÑWS WITH E‰AULT_ ATABASE = [Test ata]; rÑ "  " G     p . "     .  "        "    "        )--+"  .   "   "   " p    Œ   1 !2-3"5 -! "  "    # 7              "   !    9              "  : .      "   "   "        8   "    "      "        3  . "          E  "  ""  "  . ""          " E  "    "        p     81  p "   "       )--+. "    

 "     "   "   "             " G "          p   . ""        . "  " =83 8F8     "      p  " 1!    1  "          A   ""     p   "         USE [Test ata]; rÑ CREATE USER [Mary] ‰ÑR LÑrIN [computer_name\Mary]; rÑ *.p "   "   )--+ "        

R R

R

R

R

R R R R R R R R R R R

R R R R R R R R R R R R

R

Œ     !2-3"'c6)-0245-!  "  " "   # 7             "   !    9              "  : .      "   "   "        8   "    "      "        3  . "          E  "  ""  "  . ""          " E  "    "        p     81  *" p    "        .          E ."        . "  p   " 3     8 8=    .           !    "  1     " ?   #   7                  1"      " "             " "  ." : / 8                      "      :"  1  .  =83 8?8    "   "   " 4   " .  =83 842=8F8       "            " "  " "            " !81  "            "  1         .  "      "   CREATE *IEW vw_Names AS SELECT ProductName, Price ‰RÑM Products; rÑ " !?     E 7   F  8 8=         SELECT * ‰RÑM vw_Names; rÑ "   ! "              A*  .          K? 4       "      "    4 "      ""      "   "  "        " %-"       " ."    1   8 8=    "  .  "        " /88    "   "  " "         CREATE PRÑCE URE pr_Names @*arPrice money AS BErIN -- The print statement returns text to the user PRINT 'Products less than ' + CAST(@*arPrice AS varchar(10)); -- A second statement starts here SELECT ProductName, Price ‰RÑM vw_Names WHERE Price < @varPrice; EN

rÑ "   !  "    .   1  "       "   " "   "     " 4     % "   "   " %---

R R R R

R

R R R R R

R

R

R R

R R R R R R R R R R R R R R R R R R R

EXECUTE pr_Names 10.00; rÑ Œ     !*-3$",25"! "  " "  # 7              "   !    9              "  : .      "   "   "        8   "    "      "        3  . "          E  "  ""  "  . ""          " E  "    "        p     81  3     .  1  " 8 8= " 4   "  A*   .  1  " A*    H" .p    p "        . " 93*     ) "!81  "      p " 8= 500 rÑ id url notes counts created 601 moc.retneciyf.ved Wrong 9 2006-04-30 602 moc.retneciyf.abd Wrong 9 2007-05-21 603 moc.retneciyf.aqs Wrong 9 2007-05-23 UP ATE fyi_links SET id = id+200, counts = id*2 WHERE id >= 500 rÑ (3 row(s) affected) SELECT * ‰RÑM fyi_links WHERE id >= 500 rÑ id url notes 801 moc.retneciyf.ved Wrong 802 moc.retneciyf.abd Wrong 803 moc.retneciyf.aqs Wrong

counts 1202 1204 1206

created 2006-04-30 2007-05-19 2007-05-19

"          "  )--   "  ""         

 0 2   "2  "    *2 "   " 8   " F43 8    *2   6     "    "    9::88*=8

   .p  2       "   $ R

     "  1    "             1  "   " 8    *2   

R

p   "             1   "   " 8      

R

2    "  1    "             1  "   " 8    *2   

/      1   $ SELECT * ‰RÑM fyi_links -- Check the old values SELECT * ‰RÑM fyi_links WHERE url = 'dev.fyicenter.com' rÑ id url notes counts created 101 dev.fyicenter.com rood. 999 2006-04-30 -- Update "id" before "counts" UP ATE fyi_links SET id = id+200, counts = id*2 WHERE url = 'dev.fyicenter.com'

rÑ (1 row(s) affected) -- Check the new values SELECT * ‰RÑM fyi_links WHERE url = 'dev.fyicenter.com' rÑ id url notes counts created 301 dev.fyicenter.com rood. 202 2006-04-30 -- Reset to old values UP ATE fyi_links SET id = 101, counts = 999 WHERE url = 'dev.fyicenter.com' (1 row(s) affected) *  " " ; ; " ;;    1    7 "   " ; ;. "     . " ; ;     " ;; *"  p   .      

Π" 5'  0 "15)43"            "   "   .   #  

 1   " 8    " # "   " "      "  " " /88   "   1    "  1  $ -- Create another table CREATE TABLE fyi_rates (id INTErER, comment *ARCHAR(16)) ro -- Insert some rows in the new table INSERT INTÑ fyi_rates *ALUES (101, 'The best') ro INSERT INTÑ fyi_rates *ALUES (102, 'Well done') rÑ INSERT INTÑ fyi_rates *ALUES (103, 'Thumbs up') ro -- Update fyi_links with values from fyi_rates UP ATE fyi_links SET notes = (

SELECT comment ‰RÑM fyi_rates WHERE fyi_rates.id = fyi_links.id ) WHERE id > 0 AN id < 110 rÑ (3 row(s) affected) -- *iew the updated values SELECT * ‰RÑM fyi_links WHERE id > 0 AN id < 110 rÑ id url notes 101 dev.fyicenter.com The best 102 dba.fyicenter.com Well done 103 sqa.fyicenter.com Thumbs up

counts 999 0 NULL

created 2006-04-30 2007-05-19 2007-05-19

* "         "      "    .    1   "    . 7 ; A   M A 7 ;

c Π 5)43" 1-$ -    #       " 8     F43 8   . "  #    .       *F

  " 8    "   1    "  1  $ -- insert a new row INSERT INTÑ fyi_links (id, url, notes) *ALUES (0, 'www.fyicenter.com', 'Number one') rÑ (1 row(s) affected) -- view old values SELECT * ‰RÑM fyi_links WHERE id = 0 rÑ id url notes 0 www.fyicenter.com Number one

counts NULL

created 2007-05-23

-- make sure there is no matching row in fyi_rates SELECT * ‰RÑM fyi_rates WHERE id = 0 rÑ 0 rows -- update a subquery returning no rows UP ATE fyi_links SET notes = ( SELECT comment ‰RÑM fyi_rates WHERE fyi_rates.id = fyi_links.id )

WHERE id = 0 (1 row(s) affected) -- view new values SELECT * ‰RÑM fyi_links WHERE id = 0 rÑ id url notes 0 www.fyicenter.com NULL

counts NULL

created 2007-05-23

=; ;    "*F

 "     " # 

c Œ  5)43" 1--   #     F43 8   .   1   " "      "  " " /88      .            " . "    1   $ -- insert two rows to fyi_rates INSERT INTÑ fyi_rates *ALUES (0, 'Number 1') rÑ INSERT INTÑ fyi_rates *ALUES (0, 'Number 2') rÑ -- make sure there are 2 match rows SELECT * ‰RÑM fyi_rates WHERE id = 0 rÑ id comment 0 Number 1 0 Number 2 -- update with subquery that returns 2 rows UP ATE fyi_links SET notes = ( SELECT comment ‰RÑM fyi_rates WHERE fyi_rates.id = fyi_links.id ) WHERE id = 0 rÑ Msg 512, Level 16, State 1, Line 1 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, = or when the subquery is used as an expression. The statement has been terminated.   "     #    1  .   -%2"   .      

Π" 4 -  4 " 

      1     .  " 8 8 8    " /88      " /     8 8 8   $ -- insert a row for this test INSERT INTÑ fyi_links (url, id) *ALUES ('www.myspace.com', 301) rÑ (1 row(s) affected) -- view the inserted row SELECT id, url, notes, counts ‰RÑM fyi_links WHERE id = 301 rÑ id url notes counts 301 www.myspace.com NULL NULL -- delete one row

ELETE ‰RÑM fyi_links WHERE id = 301 rÑ (1 row(s) affected) -- try to view the deleted row SELECT id, url, notes, counts ‰RÑM fyi_links WHERE id = 301 no rows  " '-%    

Œ " 4-  04 "  6          "           . 1 " "  /88    "   "   1       '"  A 7   $ -- view rows to be deleted SELECT id, url, notes, counts ‰RÑM fyi_links WHERE id > 300 rÑ id url notes counts 801 moc.retneciyf.ved Wrong 1202 802 moc.retneciyf.abd Wrong 1204 803 moc.retneciyf.aqs Wrong 1206 -- delete multiple rows

ELETE ‰RÑM fyi_links WHERE id > 300 rÑ (3 row(s) affected)

-- try to view the deleted row SELECT id, url, notes, counts ‰RÑM fyi_links WHERE id > 300 rÑ no rows

Π" 43-  4 "          ."  $ R F " 8 8 8    "/88   R

F "  F*=3 8 3 8   

/     1       " 8 8 8   $ SELECT CÑUNT(*) ‰RÑM fyi_links rÑ 4

ELETE ‰RÑM fyi_links rÑ (4 row(s) affected) SELECT CÑUNT(*) ‰RÑM fyi_links rÑ 0

Π" 43-  "-5$23""3/           ."  $ R F " 8 8 8    "/88   R F "  F*=3 8 3 8    "  F*=3 8        " 8 8 8    "   1   "

 1   F*=3 8   $ SELECT CÑUNT(*) ‰RÑM fyi_rates rÑ 5 TRUNCATE TABLE fyi_rates rÑ SELECT CÑUNT(*) ‰RÑM fyi_rates rÑ 0

Π" ; " "1   

    E   "   #  ( $ R  L $ "  "   " E    R 2 L $ "  "   " E   . "   "      R

 "2 L $ "  "   " E   . "   "   "  

R

:2 L $ "  "   " E   ."   "     . "  "   "  

R R

Œ " c  ;   #    "   E .  " **8L2*2*   " :2p   "   1       "         "   E   $ A 7     " E    " "   "   A 7   # "   "  A    $ CREATE TABLE fyi_rates (id INTErER, comment *ARCHAR(16)) rÑ

R R R R R R R R R R R R R R R R R R R R R R R R R R R R R

R R R R

INSERT rÑ INSERT rÑ INSERT rÑ INSERT rÑ INSERT rÑ INSERT rÑ INSERT rÑ

INTÑ fyi_rates *ALUES (101, 'The best') INTÑ fyi_rates *ALUES (102, 'Well done') INTÑ fyi_rates *ALUES (103, 'Thumbs up') INTÑ fyi_rates *ALUES (204, 'Number 1') INTÑ fyi_rates *ALUES (205, 'Not bad') INTÑ fyi_rates *ALUES (206, 'rood job') INTÑ fyi_rates *ALUES (207, 'Nice tool')

SELECT fyi_links.id, fyi_links.url, fyi_rates.comment ‰RÑM fyi_links INNER JÑIN fyi_rates ÑN fyi_links.id = fyi_rates.id rÑ id url comment 101 dev.fyicenter.com The best 102 dba.fyicenter.com Well done 103 sqa.fyicenter.com Thumbs up Œ " 4 5"13$ "       1  "    .             "   1              .E  "       "  "         " :2p   " "       $ SELECT l.id, l.url, r.comment ‰RÑM fyi_links l INNER JÑIN fyi_rates r ÑN l.id = r.id rÑ id url comment

R R R R R

R R R R R R R R R R R R R R R

R R R R R R R R R R R R R

101 dev.fyicenter.com The best 102 dba.fyicenter.com Well done 103 sqa.fyicenter.com Thumbs up Œ " c    0;   #    "   E .  "  8: 2F 8L2* 2*   " :2p   "  #   "   E    $ A 7  A   " E    " "   "  A 7   # "   "  A    $ SELECT l.id, l.url, r.comment ‰RÑM fyi_links l LE‰T ÑUTER JÑIN fyi_rates r ÑN l.id = r.id rÑ id url comment 101 dev.fyicenter.com The best 102 dba.fyicenter.com Well done 103 sqa.fyicenter.com Thumbs up 104 www.mysql.com NULL 105 www.oracle.com NULL 106 www.php.net NULL 107 www.winrunner.com NULL * "    E    1 "     "   " E    "  1 ."   "        "  1   "   E  "  1      7" "    "    1   Œ " c  - 0;   #    "  " E .  " 9/ 2F 8L2* 2*   " :2p   "  #   "  " E    $ A 7  A   " E    " "   "  A 7   #  "   "  A    $ SELECT l.id, l.url, r.comment ‰RÑM fyi_links l RIrHT ÑUTER JÑIN fyi_rates r ÑN l.id = r.id rÑ id url comment 101 dev.fyicenter.com The best 102 dba.fyicenter.com Well done 103 sqa.fyicenter.com Thumbs up NULL NULL Number 1 NULL NULL Not bad NULL NULL rood job NULL NULL Nice tool * "   " E    1 "   "  "    " E   "  1 ."           "  1   "  " E  "  1       " "   7 "    1  

Π" c  %0;   #    "  E .  " :F

2F 8L2*2*    " :2p   "  #   "  E   $  A 7  A   " E    " "   "  A 7   # "   "   A    $ SELECT l.id, l.url, r.comment ‰RÑM fyi_links l

‰ULL rÑ id 101 102 103 104 105 106 107 NULL NULL NULL NULL

ÑUTER JÑIN fyi_rates r ÑN l.id = r.id url dev.fyicenter.com dba.fyicenter.com sqa.fyicenter.com www.mysql.com www.oracle.com www.php.net www.winrunner.com NULL NULL NULL NULL

comment The best Well done Thumbs up NULL NULL NULL NULL Number 1 Not bad rood job Nice tool

3  .  E  '$ R R

" "  "   " E    " "     "   " E   

R

" "   "  "   " E   

R R R R R R R R R R R

R R R R R R R R R R R R

Œ " c;   cŒ-2 B  " **8L2*2*       E . " E     " /88   " "  #  1  $ SELECT l.id, l.url, r.comment ‰RÑM fyi_links l, fyi_rates r WHERE l.id = r.id rÑ id url comment 101 dev.fyicenter.com The best 102 dba.fyicenter.com Well done 103 sqa.fyicenter.com Thumbs up Œ " $ 02  8 " " # "      B 7 "     .          " #  " 3   "      "  1  $ SELECT tag AS Category, EAR(created) AS ear, CÑUNT(*) AS Counts ‰RÑM fyi_links rRÑUP B tag, EAR(created) ÑR ER B CÑUNT(*) ESC rÑ Category ear Counts SQA 2003 1

E* 2004 1

BA 2005 1

BA 2006 1

E* 2006 1

BA 2007 1 SQA 2007 1

c  1  2"   3#   8 8=       "       "  8 8=      " #     " /88           " "         " " #     "      "     F .#      "      $ R

; 1  *# ;!   "  1   "  "     "  # 

R

; 1  *2 *# ;!   "  1    " "     " # 

R

;8sqlcmd -S localhost\sqlexpress -U sa -P ‰ Icenter 1> PRINT 'What time is it?'; 2> SELECT rET ATE(); 3> rÑ What time is it? ----------------------2007-05-19 21:51:23.797 (1 rows affected) 1> PRINT 'What time is it?'; 2> PRINT 'It''s '+CAST(rET ATE() AS N*ARCHAR(30)); 3> rÑ What time is it? It's May 19 2007 9:55PM * " " 8 8=     #  ." "     "       " 4*    

Π2  4"51   3        "    "    " " E  "$     . "     .    .       .   .    )--+. ".    . 1  .     "                )--+    G  "     $ R

81 *  !9* .* .p3

* . *6* . .8=p3 .*Fp8=.p2*86.  p3

p2*86

R R R

31   *  !: 23 . 83       !3 8 p8 p3

3 8 p8 ="    !=/3.?3=/3.  8< 

R

F  ="    !*=/3.*?3=/3. * 8< 

R R

   !*36.?3*36. p398 2"     !=F2. A?33* . 3 8.F* F88* :8. p8 3p4.    '  7"     $$> >#      "        ":"     ""      " "       .          " =$>4 :  >p     >&->    $ .\Analysis Services .\Engine .\Integrated Samples .\Integration Services .\Notification Services .\Replication .\Reporting Services

R R R R R R R R R R R

R

Π    ( 13c & "

R

    37  ""   !  "        3  7   p .""         $ %9"    )--+             )9" 15,   "    .= 7;3  7  !!).)+%C;  "      "    $>  '  7"     $$> >3  7   "        ":"     ""      " "       ."              "     $ =$>4 :  >p    >p %>p >  $ AdventureWorksLT_ ata.mdf 5,120 KB AdventureWorksLT_Log.ldf 2,048 KB Œ   3c & "     3    "       3  7 .   "      7     "  $ EXEC sp_attach_db @dbname=N'AdventureWorksLT', @filename1=N'C:\Program ‰iles\Microsoft SQL Server' +'\MSSQL.1\MSSQL\ ata\AdventureWorks_ ata.mdf', @filename2=N'C:\Program ‰iles\Microsoft SQL Server' +'\MSSQL.1\MSSQL\ ata\AdventureWorks_Log.ldf' rÑ

R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R

USE AdventureWorksLT rÑ SELECT TÑP 10 CustomerI , ‰irstName, LastName, Phone ‰RÑM SalesLT.Customer rÑ CustomerI ‰irstName LastName Phone 1 Ñrlando ree 245-555-0173 2 Keith Harris 170-555-0127 3

onna Carreras 279-555-0130 4 Janet rates 710-555-0173 5 Lucy Harrington 828-555-0186 6 Rosmarie Carroll 244-555-0112 7

ominic rash 192-555-0173 10 Kathleen rarza 150-555-0127 11 Katherine Harding 926-555-0159 12 Johnny Caprio 112-555-0191

7 7 "       3  7    

R

Π3c & "1

R R R

"    %)       3  7 $ USE AdventureWorksLT rÑ

R R R R R R R R R R R R R R R R R R R R

SELECT s.name, t.name, t.type_desc ‰RÑM sys.tables t, sys.schemas s WHERE t.schema_id = s.schema_id ÑR ER B s.name rÑ s.name t.name t.type_desc dbo Build*ersion USER_TABLE dbo ErrorLog USER_TABLE SalesLT Address USER_TABLE SalesLT Customer USER_TABLE SalesLT CustomerAddress USER_TABLE SalesLT Product USER_TABLE SalesLT ProductCategory USER_TABLE SalesLT Product escription USER_TABLE SalesLT ProductModel USER_TABLE SalesLT ProductModelProduct escription USER_TABLE SalesLT SalesÑrder etail USER_TABLE SalesLT SalesÑrderHeader USER_TABLE /    88         L  B"  $

 R R R R

Œ    3c & "         3  7 .        " ;   3 ; 3  7 $ USE AdventureWorksLT rÑ

R R R R R R R R R R R R R R R R R R R R

R R R R R R R

INSERT SalesLT.Address (AddressLine1, City, StateProvince, CountryRegion, PostalCode) *ALUES('1 Main Street', 'Java', 'Ñracle', '‰ I', 'Center') rÑ SELECT * ‰RÑM SalesLT.Address WHERE CountryRegion = '‰ I' rÑ AddressI /AddressLin1/AddressLine2/City/StateProvince /CountryRegion/PostalCode/rowguid /Modified ate 11384/1 Main Street/NULL/Java/Ñracle /‰ I/Center/6073 ‰AE-9803-4B4‰-B60E- 9742C0EE 1

/2007-05-19 19:24:44.140 c 3 3  1        E     "     "       "    3  1                 1           ."   1              "  "    "   : 1  . "    "    ; A;      1"  "  "     "   1 7 7 "      "    $

 3" "     .  "  AM%0   "   """   1 Œ " 2  "1     1  1    .  " =83 8*8 100 ÑR ER B counts ESC; rÑ SELECT rÑ id -----36470 12292 6192

TÑP 3 * ‰RÑM fyi_links_top; counts url ------- ------------------------------------------999966 dgqnvmy pyjqd toqcoupuxortasdtzvcae jonfb 999953 qebmw v qqmywe q kza wskxqns jnb 999943 p o qisvrakk hk od

Π"    5    ' "   1   .  "  "   8 8=    .  "  ;3 8?8;       "   "   1    "" 

 1   $ USE ‰yiCenter ata; rÑ ALTER *IEW fyi_links_top AS SELECT TÑP 3 id, counts, url ‰RÑM fyi_links WHERE counts > 100 ÑR ER B counts ESC;

rÑ SELECT rÑ id -----36470 12292 6192

* ‰RÑM fyi_links_top; counts url ------- ------------------------------------------999966 dgqnvmy pyjqd toqcoupuxortasdtzvcae jonfb 999953 qebmw v qqmywe q kza wskxqns jnb 999943 p o qisvrakk hk od

29 4 ' =        S "      " #   ;=      "     "" S; "    "             "     ""   "   $ R "               "   1    ""          ""  $ USE ‰yiCenter ata; rÑ ALTER *IEW fyi_links_top AS SELECT TÑP 3 id, counts, url ‰RÑM fyi_links WHERE counts > 100 ÑR ER B counts ESC; rÑ INSERT INTÑ fyi_links_top *ALUES(100001, 1000001, 'dba.fyicenter.com'); rÑ SELECT rÑ id -----100001 36470 12292

* ‰RÑM fyi_links_top;

SELECT rÑ id -----100001

TÑP 1 * ‰RÑM fyi_links ÑR ER B

counts ------1000001 999966 999953

url ------------------------------------------dba.fyicenter.com dgqnvmy pyjqd toqcoupuxortasdtzvcae jonfb qebmw v qqmywe q kza wskxqns jnb counts ESC;

url notes counts created ----------------- ----- ----------- ---------dba.fyicenter.com NULL 1000001 2007-05-19

29 54' =        S "      " #   ;=      "     "" S; "    "             "     ""   "   1       1  $ UP ATE fyi_links_top SET url = RE*ERSE(url) WHERE id = 100001; rÑ SELECT rÑ id -----100001 36470 12292

* ‰RÑM fyi_links_top;

SELECT rÑ id -----100001

TÑP 1 * ‰RÑM fyi_links ÑR ER B

counts ------1000001 999966 999953

url ------------------------------------------moc.retneciyf.abd dgqnvmy pyjqd toqcoupuxortasdtzvcae jonfb qebmw v qqmywe q kza wskxqns jnb counts ESC;

url notes counts created ----------------- ----- ----------- ---------moc.retneciyf.abd NULL 1000001 2007-05-19

29 44  ' =         S "      " #   ;=      "     "" S; "     "            "     ""   "    1       1  $

ELETE ‰RÑM fyi_links_top WHERE id = 100001; rÑ SELECT rÑ 36470 12292 6192

* ‰RÑM fyi_links_top;

SELECT rÑ id -----36470

TÑP 1 * ‰RÑM fyi_links ÑR ER B

999966 999953 999943

dgqnvmy pyjqd toqcoupuxortasdtzvcae jonfb qebmw v qqmywe q kza wskxqns jnb p o qisvrakk hk od counts ESC;

url ... ------------------------------------------- ... dgqnvmy pyjqd toqcoupuxortasdtzvcae jonfb ...

Π" 3 $2 $'   .         "   8 8=        ."   8 8=         "       1   "     "   .       "  B "   1               

    "    =?=     ?  $ CREATE *IEW fyi_links_dump AS SELECT CÑN*ERT(*ARCHAR(20),id) + ', ' + CÑN*ERT(*ARCHAR(20),counts) + ', ''' + url + '''' ‰RÑM fyi_links WHERE counts > 1000 rÑ Msg 4511, Level 16, State 1, Procedure fyi_links_dump, Line 2 Create *iew or ‰unction failed because no column name was specified for column 1. CREATE *IEW fyi_links_dump (Line) AS SELECT CÑN*ERT(*ARCHAR(20),id) + ', ' + CÑN*ERT(*ARCHAR(20),counts) + ', ''' + url + '''' ‰RÑM fyi_links WHERE counts > 1000 rÑ SELECT TÑP 3 * ‰RÑM fyi_links_dump rÑ Line -----------------------------------------------------------7600, 237946, ' eyfndw jdt lee ztejeyx l q jdh k ' 19437, 222337, ' eypx u x' 55924, 1877, ' eyq ntohxe i rtnlu riwaskzp cucoa dva c rc' "  =83 8?8   .   " 8 8=      "       .         1  

Π" 3 $2 $'   .         "   8 8=        ."   8 8=         "       1   "     "   .       "  B "   1               

    "    =?=     ?  $ CREATE *IEW fyi_links_dump AS SELECT CÑN*ERT(*ARCHAR(20),id) + ', ' + CÑN*ERT(*ARCHAR(20),counts) + ', ''' + url + ''''

‰RÑM fyi_links WHERE counts > 1000 rÑ Msg 4511, Level 16, State 1, Procedure fyi_links_dump, Line 2 Create *iew or ‰unction failed because no column name was specified for column 1. CREATE *IEW fyi_links_dump (Line) AS SELECT CÑN*ERT(*ARCHAR(20),id) + ', ' + CÑN*ERT(*ARCHAR(20),counts) + ', ''' + url + '''' ‰RÑM fyi_links WHERE counts > 1000 rÑ SELECT TÑP 3 * ‰RÑM fyi_links_dump rÑ Line -----------------------------------------------------------7600, 237946, ' eyfndw jdt lee ztejeyx l q jdh k ' 19437, 222337, ' eypx u x' 55924, 1877, ' eyq ntohxe i rtnlu riwaskzp cucoa dva c rc' "  =83 8?8   .   " 8 8=      "       .         1  

Π" /'      5 "1   .   " "  "      "  "       "      B"     : 1  . "      "  7 "  2 ."   7 "       B   "      B"     "     .         "" ; /=/8p3**9;   "  " "       3   " "    $ R R

="      B"       "   1       1        

"   1    ""      "; /=/8p3**9;$

RÑP *IEW fyi_links_view; rÑ CREATE *IEW fyi_links_view (I , ateString, CountUrl) WITH SCHEMABIN INr AS SELECT id, CÑN*ERT(*ARCHAR(16), created, 107), CÑN*ERT(*ARCHAR(20),counts)+' - '+url ‰RÑM fyi_links_copy WHERE counts > 1000; rÑ Msg 4512, Level 16, State 3, Procedure fyi_links_view,

Line 3 Cannot schema bind view 'fyi_links_view' because name 'fyi_links_copy' is invalid for schema binding. Names must be in two-part format and an object cannot reference itself. CREATE *IEW fyi_links_view (I , ateString, CountUrl) WITH SCHEMABIN INr AS SELECT id, CÑN*ERT(*ARCHAR(16), created, 107), CÑN*ERT(*ARCHAR(20),counts)+' - '+url ‰RÑM dbo.fyi_links_copy WHERE counts > 1000; rÑ Command(s) completed successfully.

RÑP TABLE fyi_links_copy; rÑ Msg 3729, Level 16, State 1, Line 1 Cannot RÑP TABLE 'fyi_links_copy' because it is being referenced by object 'fyi_links_view'. "     "  =83 8?8    "   1"      " " "     "     " 24 3 8    "  "  "       "      

Π" 2 '   "       "    .       1"    "  "   1    ""    #     1  

RÑP *IEW fyi_links_view; rÑ CREATE *IEW fyi_links_view (I , UrlReversed) AS SELECT id, RE*ERSE(url) ‰RÑM fyi_links_copy WHERE counts > 1000; rÑ CREATE UNIQUE CLUSTERE IN EX date_string ÑN fyi_links_view (I ); rÑ Cannot create index on view 'fyi_links_view' because the view is not schema bound. ALTER *IEW fyi_links_view (I , UrlReversed)

WITH SCHEMABIN INr AS SELECT id, RE*ERSE(url) ‰RÑM dbo.fyi_links_copy WHERE counts > 1000; rÑ CREATE UNIQUE CLUSTERE IN EX date_string ÑN fyi_links_view (I ); rÑ EXEC SP_HELP fyi_links_view; rÑ index_name index_description index_keys ----------- ------------------------------------ ---------date_string clustered, unique located on PRIMAR I

c 3  )  3          !    "   "    3       1     " 8NULL is returning ‰ALSE' ELSE PRINT '1>NULL is not returning ‰ALSE' rÑ 1>NULL is not returning ‰ALSE 3"   " ;B:6BM*F

;    F8:3 8    "   . *F

$ I‰ '‰ I'=NULL PRINT '''‰ I''=NULL returns TRUE' ELSE PRINT '''‰ I''=NULL does not return TRUE' rÑ '‰ I'=NULL does not return TRUE I‰ NÑT '‰ I'=NULL PRINT '''‰ I''=NULL returns ‰ALSE' ELSE PRINT '''‰ I''=NULL does not return ‰ALSE' rÑ '‰ I'=NULL does not return ‰ALSE

c Π$5

'3 / 0  *F

            ."       "     :3*  .:3 8 7      *F

 "      G       $ AN

TRUE ‰ALSE NULL TRUE true false null ‰ALSE false false false NULL null false null :2  . F8 7      *F

 "      G       $

ÑR TRUE ‰ALSE NULL

TRUE true true true

‰ALSE true false null

NULL true null null

"    "" *F

3*:3 8 :3 8$ I‰ 0=NULL AN 0=1 PRINT 'NULL AN ‰ALSE returns TRUE' ELSE PRINT 'NULL AN ‰ALSE does not returns TRUE' rÑ NULL AN ‰ALSE does not returns TRUE I‰ NÑT (0=NULL AN 0=1) PRINT 'NULL AN ‰ALSE returns ‰ALSE' ELSE PRINT 'NULL AN ‰ALSE does not returns ‰ALSE' rÑ NULL AN ‰ALSE returns ‰ALSE

Π" "$5

')  :  .  "    1   "*F

    *F

           1      *F

     1  *F

  ."  "      $ expression IS NULL -- Returns TRUE if the expression is a NULL value expression IS NÑT NULL -- Returns TRUE if the expression is not a NULL value "    "" *F

 *2 *F

$ I‰ 0 IS NULL PRINT 'TRUE' ELSE PRINT '‰ALSE'; rÑ ‰ALSE I‰ NULL IS NULL PRINT 'TRUE' ELSE PRINT '‰ALSE'; rÑ TRUE I‰ 1+NULL IS NULL PRINT 'TRUE' ELSE PRINT '‰ALSE'; rÑ TRUE I‰ 'NULL' IS NÑT NULL PRINT 'TRUE' ELSE PRINT '‰ALSE';

rÑ TRUE

Π" -$5

'   $5

+. 3    .*F

       1     "      *F

   . *F

       "     . 7  -.BB.B*F

B."  1               !    *F

"    *F

    1  $ ISNULL(expression, replacement) -- Returns "expression", if it is not NULL -- Returns "replacement", if "expression" is NULL "   1   ""     *F

   K  A   $ USE ‰yiCenter ata; rÑ CREATE PRÑCE URE welcome @first_name *ARCHAR(20), @middle_initial *ARCHAR(1), @last_name *ARCHAR(20) AS PRINT 'Hello '+@first_name + ' '+@middle_initial + ' '+@last_name; PRINT 'Hello '+@first_name + ' '+ISNULL(@middle_initial,'') + ' '+@last_name; rÑ EXEC welcome 'John', 'W', 'King'; rÑ Hello John W King Hello John W King EXEC welcome 'John', NULL, 'King'; rÑ Hello John

King

"  4*     "      7     *F

  

Π" -*' $5

 $5

%+.     "         "  "*F

             *F

:" $

NULLI‰(expression, value) -- Returns NULL if "expression" equals to value" -- Returns "expression", otherwise *F

:     "    *F

 "    "   1   *F

:$ USE ‰yiCenter ata; rÑ SELECT id, counts ‰RÑM fyi_links; rÑ id counts ----------- ----------101 NULL 102 8 1101 NULL 202 NULL 2101 NULL 2102 NULL 301 NULL 302 NULL -- converting NULL to 0 UP ATE fyi_links SET counts=ISNULL(counts,0); rÑ SELECT id, counts ‰RÑM fyi_links; rÑ id counts ----------- ----------101 0 102 8 1101 0 202 0 2101 0 2102 0 301 0 302 0 -- converting 0 to NULL UP ATE fyi_links SET counts=NULLI‰(counts,0); rÑ SELECT id, counts ‰RÑM fyi_links; rÑ id counts ----------- ----------101 NULL

102 1101 202 2101 2102 301 302

8 NULL NULL NULL NULL NULL NULL

c    5      )--+           ' $ R

   !8        "     : 1  .             

R

4   !8       "  #      : 1  .         

R

4   !         "   4         7    : 1  .;F  ;            .  ;; ;F  ;;;        . ;F;* ;F;  ;F  ;     ;;

   .      "   #  ;"  S;H       "   #  ;"    E S;H      "   #   ;6     "   "   E ;    )--+             G  "  "     " "   $

4  p 



c 3 )5      )--+                $ R

 ! 4   $       * 7   !F           

R

   ! 4   $     !F          

R

    ! 4   $    F !F           

         .              "      2   .      "            "    

           "    .     ""         " "       "     .       "           "      

c   )   " -9             "  "     ""    "    "       "      "          7      "     "  "           S "      !"       "    "   : 1  .  "    ""     ; ;."       ; ; "     2 F 1 ."         ;"  ;" "       "               A  ." "            "      "   1  $ -- ‰ind out your security principal at the server level PRINT Suser_Sname(); rÑ sa "  1  ""  ; ; "     "   

c   ) 41 " -9             "  "     ""    "    "        "      "          7      "       "  "             S "      !"     "      " "       : 1  .   "    ""    ; ;.  ;: =    ; "      .      ; ;        ;: =    ;     "             ;: =    ; "       2 F 1 ."         ;"  ;" "       "              F A*  ." "             "     "         "   1  $ PRINT Suser_Sname(); rÑ sa USE ‰yiCenter ata; rÑ -- ‰ind out your security principal at the database level PRINT User_Name(); rÑ dbo

"  1  "" ;;     ;: =    ;"      ; ;

Π" 2$ $     .    "  " ; ; 3           "  "       "   .   ; ;" " 3

     6              " .  "           .  " ;=83 8 29*;        1 7  " $ CREATE LÑrIN login_name WITH PASSWÑR = 'password' ;=83 8 29*;   .  "    "         7 ; ; "   1   $ -- Login with 'sa' -- Create new login names CREATE LÑrIN ‰ I_ BA WITH PASSWÑR = 'AB _I ‰' rÑ Command(s) completed successfully. CREATE LÑrIN ‰yi_Login WITH PASSWÑR = 'I ‰' rÑ

Œ " '    24"  " # 7               "  =p." "  7 "     .            /   "   $        "   $ C:\>SQLCM -S LÑCALHÑST\SQLEXPRESS -U ‰ I_ BA -P AB _I ‰ 1> PRINT Suser_Sname(); 2> rÑ ‰ I_ BA 1> QUIT C:\> " ":6A3      "    *"  $ C:\>SQLCM -S LÑCALHÑST\SQLEXPRESS -U ‰ I_ E* -P AB _I ‰ Msg 18456, Level 14, State 1, Server LÑCALHÑST\SQLEXPRESS, Line 1 Login failed for user '‰ I_ E*'. C:\> " ":6A8?     "     

Π"  3 $   

           "   .  "   .   A    " "   1   $ -- Login with sa SELECT name, sid, type, type_desc ‰RÑM sys.server_principals WHERE type = 'S'; rÑ name sid type type_desc -------- ----------------------------------- ---- --------sa 0x01 S SQL_LÑrIN ‰ I_ BA 0x348A‰32B3B58CB40B67A5‰5B7086B96E S SQL_LÑrIN ‰yi_Login 0x5EB8701EAEBAA74‰86‰C‰5B 8E37B8C5 S SQL_LÑrIN "    "    "  

Œ " 2   )   $    "  " "    .   "   ""  ;3 8 29*;    " "   1  $ -- Login with sa ALTER LÑrIN ‰ I_ BA WITH PASSWÑR = 'fyicenter'; rÑ Command(s) completed successfully. :6A3B  "     ""  =p$ C:\>SQLCM -S LÑCALHÑST\SQLEXPRESS -U ‰ I_ BA -P fyicenter 1> QUIT 6   " ;3 8 29*;"   

Œ " 2   $  "      .  " ;3 8 29*;    " "    1  $ -- Login with "sa" -- Change login name ALTER LÑrIN ‰yi_Login WITH NAME = ba_Login; rÑ -- *iew login names SELECT name, sid, type, type_desc ‰RÑM sys.server_principals WHERE type = 'S'; rÑ name sid type type_desc -------- ----------------------------------- ---- ---------

sa 0x01 ‰ I_ BA 0x348A‰32B3B58CB40B67A5‰5B7086B96E

ba_Login 0x5EB8701EAEBAA74‰86‰C‰5B 8E37B8C5

S S S

SQL_LÑrIN SQL_LÑrIN SQL_LÑrIN

Œ " 41 $            .  " ;3 8 29*;    "  3 87        .  " 8*3 87  "   1    ""          ; A  ;$ -- Login with "sa" -- isable a login ALTER LÑrIN ‰yi_Login ISABLE; -- *iew login status SELECT name, type, type_desc, is_disabled ‰RÑM sys.server_principals WHERE type = 'S'; rÑ name type type_desc is_disabled ----------- ---- ---------- ----------sa S SQL_LÑrIN 0 ‰ I_ BA S SQL_LÑrIN 0

ba_Login S SQL_LÑrIN 1 *  ""       $ C:\>SQLCM -S LÑCALHÑST\SQLEXPRESS -U ba_Login -P I ‰ Msg 18470, Level 14, State 1, Server LÑCALHÑST\SQLEXPRESS Login failed for user ' ba_Login'. Reason: The account is disabled. C:\> "           ; A  ;$ -- Login with "sa" -- Enable a login ALTER LÑrIN ‰yi_Login ENABLE;

Π" 4 $ B 7       ."     " ;24 29*;     " "   1  $ -- Login with "sa"

RÑP LÑrIN ba_Login; rÑ Command(s) completed successfully.

-- *iew login names SELECT name, sid, type, type_desc ‰RÑM sys.server_principals WHERE type = 'S'; rÑ name sid type type_desc -------- ----------------------------------- ---- --------sa 0x01 S SQL_LÑrIN ‰ I_ BA 0x348A‰32B3B58CB40B67A5‰5B7086B96E S SQL_LÑrIN

Π" 25$41 F           "              

       .        "       7 "     =          " ;=83 8F8;    " "   1   $ -- Login with "sa" -- Create a login CREATE LÑrIN ‰yi_Login WITH PASSWÑR = 'I ‰' rÑ -- Select a database USE ‰yiCenter ata; rÑ -- Create a user and link it to a login CREATE USER ‰yi_User ‰ÑR LÑrIN ‰yi_Login; rÑ

   ;: A  ;"         ;: =    ;""    ;: AF ;

Œ "  35$41                  .  "   .     A    " "   1   $ -- Login with sa -- Select a database USE ‰yiCenter ata; rÑ -- List all user names SELECT name, sid, type, type_desc ‰RÑM sys.database_principals WHERE type = 'S';

rÑ name -------------------dbo guest IN‰ÑRMATIÑN_SCHEMA sys ‰yi_User (5 row(s) affected)

sid -----------------------0x01 0x00 NULL NULL 0x5EB8701EAEBAA74‰86‰...

type ---S S S S S

type_desc --------SQL_USER SQL_USER SQL_USER SQL_USER SQL_USER

3  ."    +       ;: =    ;(          "        2"   ;: AF ;     "    

Π" %  $ & *5$ 7             " "     7 "     . " 7"   "      "   $ R

8 "         # 

R

"       7     ."    B  "    

"     7     " "  "     "   1     "" "    "   7 "    ;: AF ;$ -- Login with sa USE ‰yiCenter ata; rÑ SELECT u.name AS User_Name, l.name AS Login_Name, u.sid ‰RÑM sys.server_principals l, sys.database_principals u WHERE l.sid = u.sid AN u.name = '‰yi_User'; rÑ User_Name Login_Name sid ---------- ----------- ---------------------------------‰yi_User ‰yi_Login 0x5EB8701EAEBAA74‰86‰C‰5B 8E37B8C5 (1 row(s) affected)

Œ " ' 5  24"  " # 7                 "  =p6   "   .  "     . " 7" "     7 "       "         "   $ C:\>SQLCM -S LÑCALHÑST\SQLEXPRESS -U ‰yi_Login -P I ‰ 1> USE ‰yiCenter ata;

2> rÑ Changed database context to '‰yiCenter ata'. 1> PRINT User_Name(); 2> rÑ ‰yi_User " " ;: AF ;     ;: =    ;  7    ;: A  ;

Œ " 2   $ 415  "  "     1       .  " ;3 8F8;     " "   1    $ -- Login with "sa" USE ‰yiCenter ata; rÑ ALTER USER ‰yi_User WITH NAME = ba_User; rÑ -- List all user names SELECT name, sid, type, type_desc ‰RÑM sys.database_principals WHERE type = 'S'; rÑ name sid type -------------------- ------------------------ ---dbo 0x01 S guest 0x00 S IN‰ÑRMATIÑN_SCHEMA NULL S sys NULL S

ba_User 0x5EB8701EAEBAA74‰86‰... S

type_desc --------SQL_USER SQL_USER SQL_USER SQL_USER SQL_USER

" "   "  ;: AF ;; AF ;

Œ " 4 415 B 7         ."   "   " ;24 F8;    "   1   ""   ; AF ;$ -- Login with "sa" USE ‰yiCenter ata; rÑ

RÑP USER ba_User; rÑ

-- List all user names SELECT name, sid, type, type_desc ‰RÑM sys.database_principals WHERE type = 'S'; name sid type -------------------- ------------------------ ---dbo 0x01 S guest 0x00 S IN‰ÑRMATIÑN_SCHEMA NULL S sys NULL S

type_desc --------SQL_USER SQL_USER SQL_USER SQL_USER

F ; AF ;"       %3 (2    04/22  4 $    è  )è    * +  &         & * +   +  ,-(,   % ,-(,  * +  &!è  

c 0412  +04/2. 2=.2     =   .   34            p          "                     "" 2=       .   "   #   $ R

32=        "       

R

32=*   *  ! 2=       " 2=         

R

32=343   4              "       """ 2= 

: 1  .        4/4 "" 2= .  7   " $ R

32= p   ! " 2=       "    

R

32=*!6      " 2=   

R

32=34 4/4   ! " 34      " 4/4   

Π" 3$4 $  04/24    3 " " 2=    "       "   . "  1   2=          *    *   "" 2=   3   $ R

9=4  

R R R

93         2= " 2=   3    " 9 * 

R

= 7" 3

6"   2=        2= "  "  7 "    .  "    2=  "   )---5+%%%0--.   ?')

.  5J(J)--($





  ;   ;" 2=  .  7;:  "; " ;=   *        ; G  "=   ""  1   "     *

Œ " 4  $  4 $ =  "   ."   " ;=   *        ; G ."  ' $*  .   .       $ Name: ‰ I_SQL_SER*ER

escription: ‰ Icenter.com SQL Server Server: LÑCALHÑST  "    $





* " "             "    "  7  "    "  "      "  1  . 2=3 /2  "  "        = 7* 1    ""  1   "    *

Π" )     $04/24 $ =  "   3  7 * 1"   " ;=   *        ; G ." "    7         .        "   ; "    "             "  3      $; ;  4  $;:6  ; "    $





   " ; ; "         . "          "  ;:6  ; "       "    ; ;     = 7* 1    ""  1   "    *

c 39 *  c 2 $04/24 $ =  "   3  7 * 1"       .2=      "     ""        3        .      1  " $ Connection failed: SQLState: '01000' SQL Server Error: 53 [Microsoft][Ñ BC SQL Server river][ BNETLIB] ConnectionÑpen(Connect()). Connection failed:

SQLState: '08001' SQL Server Error: 17 [Microsoft][Ñ BC SQL Server river][ BNETLIB] SQL Server does not exist or access denied.  "    $





"    "   $ R R

    !6                7   7  !6 " 7"        

R

    !6        

"   "            "    #  "      =   ""  1       7   7   

c 3 -   $ &2     .   )--+81 8            $ R

"  p !         "    "     "  "  "      : 1  .     =p"      "  .   " ;"  p ;

     "          "        " ; =4J4; :    "    "    "   "    ."  ;"  p ;.     " ; =4J4;"      2=p         "  #  " ; =4J4; "      "       7  .          "     "    ."     #          7  $ R         "     "   R

8  "  =4J4"    

R R

Π"    /                "            "    7          "        7  . "   $

R R R R R R R

R R R R

R R R R R R

R R R R R R R R R R R R

%9=4  @3      )  7;   ; "     " '  7;    ; "    1" (="  " ;   ;   3   "  7"   " ;    ;   "   Π" 1"2)6))         ."  =4J4  "               7          "    .    "  =4J4"    "  $ %9 @34 @p    )--+@=    @    =   p    )  7;   )--+* 7=   ; "         '= 7;4 8
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF