{"id":726,"date":"2004-06-12T22:24:55","date_gmt":"2004-06-12T22:24:55","guid":{"rendered":"\/blogs\/kimberly\/post\/MSDN-Webcast-SQL-Index-Tuning-QA-General-Questions.aspx"},"modified":"2013-01-11T23:14:06","modified_gmt":"2013-01-12T07:14:06","slug":"msdn-webcast-sql-index-tuning-qa-general-questions","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/msdn-webcast-sql-index-tuning-qa-general-questions\/","title":{"rendered":"MSDN Webcast SQL Index Tuning Q&#038;A: General Questions"},"content":{"rendered":"<p><P><STRONG><FONT size=4>General Questions:<\/FONT><\/STRONG><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><B style=\"mso-bidi-font-weight: normal\"><FONT color=#000000><FONT size=3><FONT face=Arial>Q: If you want to know the value of the key prior to your insert statement, how can you use identity? <?xml:namespace prefix = o ns = \"urn:schemas-microsoft-com:office:office\" \/><o:p><\/o:p><\/FONT><\/FONT><\/FONT><\/B><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><FONT face=Arial color=#000000 size=3>You could insert a &#8220;place-holder&#8221; row (<I style=\"mso-bidi-font-style: normal\">i.e. a row that uses only defaults and\/or just basic information so that you can get the @@identity of the row<\/I>) and then come back later to update the data values. However, be very cautious with this approach. If you insert a lot of NULL values and have a very narrow row inserted then when you come back to update it (and therefore widen the variable width columns, if any) you can end up creating a lot of fragmentation. To minimize this, make sure to use default values (i.e. DEFAULT constraints) to pre-allocate space and reduce fragmentation.<\/FONT><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><o:p><FONT face=Arial color=#000000 size=3>&nbsp;<\/FONT><\/o:p><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><B style=\"mso-bidi-font-weight: normal\"><FONT color=#000000><FONT size=3><FONT face=Arial>Q: Can you give me a brief definition of a doubly-linked list?<o:p><\/o:p><\/FONT><\/FONT><\/FONT><\/B><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><FONT face=Arial color=#000000 size=3>Speaking directly to the &#8220;leaf-level&#8221; of an index the doubly linked list refers to the pages that contain the index data &#8211; in indexed order. Since there&#8217;s likely to be more than one row per page and since an index implies order; the pages are &#8220;linked&#8221; to provide that order logically.<\/FONT><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><FONT face=Arial color=#000000 size=3>The NIST (National Institute of Standards) also has a series of &#8220;data structures&#8221; definitions and doubly-linked list is <a href=\"http:\/\/xlinux.nist.gov\/dads\/\/HTML\/doublyLinkedList.html\">here<\/a>.<\/FONT><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><o:p><FONT face=Arial color=#000000 size=3>&nbsp;<\/FONT><\/o:p><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><FONT face=Arial color=#000000 size=3>And for a bit more about SQL internals &#8211; SQL Server 2000 (actually 7.0 and higher) uses 8K pages. Each page has a 96 byte header &#8211; [a very small] part of which is used to store this previous-page and next-page page pointers. As for how many rows SQL Server will store; that depends on the width of the row. You can divide 8096 by your average row size to get an idea of how many rows you will be storing and you can use DBCC SHOWCONTIG (&#8216;tablename&#8217;) WITH TABLERESULTS to see information columns labeled MinimumRecordSize, MaximumRecordSize, and AverageRecordSize for more specific table-related values. There is a maximum limit of 8060 bytes for a single inserted row. <\/FONT><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><o:p><FONT face=Arial color=#000000 size=3>&nbsp;<\/FONT><\/o:p><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><B style=\"mso-bidi-font-weight: normal\"><FONT color=#000000><FONT size=3><FONT face=Arial>Q: Well, this is a live meeting question and I should have reminded you all! But &#8211; for future reference&#8230; How do I see the demo in full-screen mode?<o:p><\/o:p><\/FONT><\/FONT><\/FONT><\/B><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><FONT face=Arial color=#000000 size=3>Press Control + H when the webcast begins a demo.<\/FONT><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><o:p><FONT face=Arial color=#000000 size=3>&nbsp;<\/FONT><\/o:p><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><B style=\"mso-bidi-font-weight: normal\"><FONT color=#000000><FONT size=3><FONT face=Arial>Q: Could you please give an example of a foreign key constraint?<o:p><\/o:p><\/FONT><\/FONT><\/FONT><\/B><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><FONT face=Arial color=#000000 size=3>A foreign key constraint is used to enforce referential integrity between two columns of the same or different tables. For example, you might create two tables: Employees and Departments. Because each employee can only be in one department, you can enforce this relationship with keys. First, make the DepartmentID (of the Departments table) a Primary Key and then make the DepartmentID column of the Employee Table reference Departments. Here&#8217;s a small snippet of pseudo code.<\/FONT><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><o:p><FONT face=Arial color=#000000 size=3>&nbsp;<\/FONT><\/o:p><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><FONT face=Arial color=#000000 size=3>There are lots of good references out there on database design and constraints and I&#8217;ve heard good things about <I style=\"mso-bidi-font-style: normal\"><a href=\"http:\/\/www.bookfinder.us\/review0\/0201752840.html\" class=\"broken_link\">Database Design for Mere Mortals<\/a><\/I> by Mike Hernandez.<\/FONT><FONT face=Arial color=#000000 size=3> <\/FONT><FONT face=Arial color=#000000 size=3>And, here&#8217;s an article on MSDN titled: <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/dnsql2k\/html\/sql_refintegrity.asp?frame=true\">Implementing Referential Integrity and Cascading Actions<\/a>&nbsp;by Itzik Ben-Gan.<\/FONT><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><o:p><FONT face=Arial color=#000000 size=3>&nbsp;<\/FONT><\/o:p><\/P><br \/>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><B style=\"mso-bidi-font-weight: normal\"><FONT size=3><FONT face=Arial><FONT color=#000000>Q: Why does SQL Server allocate up the all of the memory? Even if I stop the service in short time it&#8217;s the same?<BR><\/FONT><\/FONT><\/FONT><\/B><SPAN style=\"FONT-SIZE: 12pt; FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA\"><FONT color=#000000>Since SQL Server is typically run as a dedicated service in production environments, SQL Server typically allocates memory to have it available when it needs the memory. If it detects memory pressure SQL Server will release those pages. If you&#8217;d like to configure memory for a specific max server memory and\/or min server memory, you can check out the books online as well as this MSDN article titled: <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/dnsqldev\/html\/sqldev_01262004.asp\">Inside SQL Server 2000&#8217;s Memory Management Facilities<\/a> by <?xml:namespace prefix = st1 ns = \"urn:schemas-microsoft-com:office:smarttags\" \/><st1:PersonName w:st=\"on\">Ken Henderson<\/st1:PersonName><\/FONT><FONT color=#000000>.<\/FONT><\/SPAN><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>General Questions: Q: If you want to know the value of the key prior to your insert statement, how can you use identity? You could insert a &#8220;place-holder&#8221; row (i.e. a row that uses only defaults and\/or just basic information so that you can get the @@identity of the row) and then come back later [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,36,58],"tags":[],"class_list":["post-726","post","type-post","status-publish","format-standard","hentry","category-events","category-indexes","category-resources"],"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts\/726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/comments?post=726"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/posts\/726\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/media?parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/categories?post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/kimberly\/wp-json\/wp\/v2\/tags?post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}