SQL DBA Interview question and answer
<!--
/* Font Definitions */
@font-face
{font-family:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:ËÎÌå;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:0;
mso-generic-font-family:roman;
mso-font-pitch:variable;
mso-font-signature:-1610611985 1107304683 0 0 159 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-1610611985 1073750139 0 0 159 0;}
@font-face
{font-family:"\@SimSun";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin-top:0cm;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:SimSun;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:SimSun;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
.MsoPapDefault
{mso-style-type:export-only;
margin-bottom:10.0pt;
Ïà¹ØÎĵµ£º
¡¡
¡¡¡¡1. ʹÓÃ%TYPE
¡¡¡¡ÔÚÐí¶àÇé¿öÏ£¬PL/SQL±äÁ¿¿ÉÒÔÓÃÀ´´æ´¢ÔÚÊý¾Ý¿â±íÖеÄÊý¾Ý¡£ÔÚÕâÖÖÇé¿öÏ£¬±äÁ¿Ó¦¸ÃÓµÓÐÓë±íÁÐÏàͬµÄÀàÐÍ¡£ÀýÈ磬students±íµÄfirst_nameÁеÄÀàÐÍΪVARCHAR2(20),ÎÒÃÇ¿ÉÒÔ°´ÕÕÏÂÊö·½Ê½ÉùÃ÷Ò»¸ö±äÁ¿£º
¡¡¡¡DECLARE
¡¡¡¡ v_FirstName VARCHAR2(20);
¡¡
¡¡µ«ÊÇÈç¹ûfirst_nameÁе͍Òå¸Ä±äÁ ......
Èç¹û£¬ÏÖÔÚÓÐÁ½ÕűíA(id,xx.xx...),C(id,Cid,xx,xx...)£¬Ô¤ÊµÏÖCÖеÄidÓëA ÖÐid¼¶ÁªÉ¾³ý¡¢¼¶Áª¸üÐÂ/Êý¾Ýͬ²½£¬¿ÉÓÐÁ½ÖÖʵÏÖ·½Ê½£º
Ò».
ÀûÓÃsql server×Ô´øµÄ¼¶ÁªÉ¾³ý¡¢¼¶Áª¸üй¦ÄÜ£¬¼´ÆäÍâ¼üÔ¼ÊøÍ¾¾¶
alter table dbo.C
add constraint FK_C_A_AID
foreign key(AID) references dbo.A(AID)
on delet ......
»Ö¸´Ä£Ê½ÊÇÊý¾Ý¿âµÄÒ»ÖÖÌØÐÔ,Ëü¿ØÖÆ×ÅÊý¾Ý¿â±¸·ÝºÍ»¹ÔµÄ»ù±¾ÐÐΪ.
sql server ÌṩÁËÈýÖÖ»Ö¸´Ä£Ê½,ËûÃǾö¶¨ÁËÓжàÉÙºÍʲôÑùµÄÊý¾Ý¿ÉÒÔ±»±¸·ÝÏÂÀ´.
1.¼òµ¥»Ö¸´Ä£Ê½
Ö÷ÒªÓ¦ÓÃÓÚСÐÍÊý¾Ý¿âºÍ²»¾³£¸Ä±äµÄÊý¾Ý
2.ÍêÕû»Ö¸´Ä£Ê½
¿ÉÒÔÔÚ×î´ó·¶Î§ÄÚ·ÀÖ¹³öÏÖ¹ÊÕÏʱ¶ªÊ§Êý¾Ý,Ëü°üÀ¨Êý¾Ý¿â±¸·ÝºÍʳÎïÈÕÖ¾±¸·Ý,²¢Ìá¹ ......
ÈôÒªÊÕËõÌØ¶¨Êý¾Ý¿âµÄËùÓÐÊý¾ÝºÍÈÕÖ¾Îļþ£¬ÇëÖ´ÐÐ DBCC SHRINKDATABASE ÃüÁî¡£ÈôÒªÒ»´ÎÊÕËõÒ»¸öÌØ¶¨Êý¾Ý¿âÖеÄÒ»¸öÊý¾Ý»òÈÕÖ¾Îļþ£¬ÇëÖ´ÐÐ DBCC SHRINKFILE
ÃüÁî¡£
ÈôÒª²é¿´Êý¾Ý¿âÖе±Ç°µÄ¿ÉÓã¨Î´·ÖÅ䣩¿Õ¼äÁ¿£¬ÇëÔËÐÐ sp_spaceused
¡£
¿ÉÔÚ½ø³ÌÖеÄÈÎÒ»µãÍ£Ö¹ DBCC SHRINKDATABASE ²Ù×÷£¬ÈκÎÒÑÍê³ÉµÄ¹¤×÷¶¼½«±£Áô¡£ ......