Laden...
|
|
|
|
|
|
Question of the Day |
Today's question (by tomaz.kastrun): | |
R function kronecker() | |
What does the following script R return (the function is part of the base R Package): kronecker(1:2,t(1:3)) | |
Think you know the answer? Click here, and find out if you are right. |
Yesterday's Question of the Day (by Junior Galvão - MVP) |
Self-numbered primary key creation I have a database, called Stock, and I have the need to create a new table, called Orders, according to the code below: -- Accessing the Stock Database -- Use Stocks Go -- Creating the Orders Table -- Create Table Orders (ID Int IDENTITY(1,1) Not Null Primary Key, CustomerID Int Not Null, SalesPersonID Varchar(30) Not Null, Quantity smallint Not Null, NumericValue numeric(18, 2) Not Null, Today Date Not Null) GoRight after creating the table, you choose to use some recursive CTEs the amount of 100,000 rows of records in the Orders table: Knowing that from the moment we create a new table containing a primary key, Microsoft SQL Server adds a Statistic, a feature that aims to help us get the dataset through the Select command faster. What will happen to the Histogram, its column structure that indicates how often data will be created?
Answer: 2 - Your column structure that indicates the frequency of data will be created but at this time without the data bands that represent the frequency of data queried. Explanation: The correct answer is number 2. The Histogram component, which relates to the Statistics of tables and indexes, will have its frequency distribution of data queried from the first effective manipulation performed to our Orders table accompanied by the Where clause declared for one or more columns. To understand and simulate this behavior, run the following shared code blocks: -- Querying the Statistics Metadata -- -- Consultando os Metadados das Estatísticas -- Select OBJECT_NAME(s.object_id) As Tabela, s.name As Estatistica, s.auto_created As Tipo, c.name As Coluna from sys.stats_columns sc Inner Join sys.columns c ON sc.object_id = c.object_id AND sc.column_id = c.column_id Inner Join sys.stats s ON sc.object_id = s.object_id AND sc.stats_id = s.stats_id Where OBJECT_NAME(s.object_id) = 'Orders' Go -- Introducing the Histogram -- DBCC SHOW_STATISTICS("Pedidos", [type here the name of the statistic created for primary key/) With Histogram GoAnd now, I leave it to you to process the Select command by using the Where clause, so that the Histogram can create the data distribution range. References: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-statistics-transact-sql?WT.mc_id=DP-MVP-38732&view=sql-server-ver15 https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-show-statistics-transact-sql?WT.mc_id=DP-MVP-38732&view=sql-server-ver15 |
Database Pros Who Need Your Help |
Here's a few of the new posts today on the forums. To see more, visit the forums. |
SQL Server 2017 - Administration |
SQL input parameters are defaulting to nvarchar causing full table scans - When our applications are submitting SQL via ADO.Net, with input parameters, the parameter definitions are defaulting to nvarchar. If that field is defined as a varchar and an index on the database table, the index is not used resulting in a scan instead of a seek. We are converting from Teradata to SQL Server so […] |
Need to learn about ALWAYS ON High Availability Group from scratch - any advice? - Please advise me what resources I can use to learn rather deeply about Always ON if I never have learned or seen it before but need to be up to some knowledge within a couple of days (having started in a new Sr DBA role...) . What are the key pre-requisite knowledge that I must […] |
SQL Server 2017 - Development |
SQL - How to compare data of a column while iterating row by row and insert new - I have the below data in an SQL Server(2017) table POS_ID Term Code Status IsActive TR 101 In Progress true TR 102 In Progress true TR 103 In Progress true CA 151 In Progress true CA 152 In Progress true DA 161 In Progress true The requirement is I want to iterate each row and […] |
SQL Server 2016 - Administration |
PARALLEL_REDO_WORKER_WAIT_WORK.: Not sure how relevant this may be.. - Attached file shows the top waits... PARALLEL_REDO_WORKER_WAIT_WORK.: Not sure how relevant this may be for this morning Latency reported by multiple users accessing a number of web pages and apps that connect to this server.. just seeing it first time But this wait type has been predominantly much higher than all other waits. Comparing to […] |
Distributed Availability group - Is there a guideline or does anyone have any step by step process on removing Distributed Availability group between 2 servers properly? I am trying to beak it a part because the secondary server (forwarder) is old and ready to be decommissioned. This is how servers are setup: DAG between SQL1P (forwarder) and SQL2P (primary) […] |
MAXDOP Setting - When upgrading and creating my new SQL server farm on 2016 I researched things to set on the server, one being MAXDOP setting. From reading up about the setting I have set it at 8 on a server that has 8 logical cores. The server is a VM and I believe it has a single […] |
SQL Server 2016 - Development and T-SQL |
Is Index Fragmentation Still Relevant in a Cloud Base/Virtual SQL Server Setup - We moved our mission critical DB to the software vendors private cloud. This meant we (my company) no longer handle the setup and maintenance of the SQL server hosting the DB. I don't know how the vendor has it setup (our access is limited) but I'm certain everything is virtualized, no more separate physical drives […] |
Administration - SQL Server 2014 |
Data type Date - Previously we had some issues with deadlocks caused by transaction that happen so fast that the current timestamp column is not accurate enough to prevent a collision. To prevent such an occurrence we need to change the data type used by the timestamp column in order to make it more precise, both for existing tables […] |
Can we know the detailed information of a table ? - we can use sp_spaceused to know how many space reservred by a table and know how many spaces for data space and index space, but if there is a approach to know the following informations of table , thanks! how can we know the start page and end page used for storing data for a […] |
SQL Server 2012 - T-SQL |
Updating from previous row until next value is found - I am trying to create an update that will update a value from previous row until the next none null value is found then update with that value. For instance in my table there are 2 columns SeqNum and AcctNum. The SeqNum will always start with 0000003 and the AcctNum will have a value and […] |
SQL Server 2019 - Administration |
SQL 2012 AlwaysON migration - We have a SQL AlwaysON setup on windows 2012 R2 / SQL 2012 (to latest patch). We want to migrate to 2019. Can we add to the cluster and to the AlwaysON a Node3 and Node4 (Windows 2019 / SQL 2019) Then failover to Node3 and REMOVE Node1 and Node2. Will that migration work? Has […] |
Raising errors between 1 and 13000 - Hello, I've been struggling with a task which requires me to raise a number of errors for testing purposes. Of course the time consuming errors are between 1 and 13000. I've managed to do them, but I need to do it several times on multiple test instances and I wanted to ask if there's a […] |
Restore - what happens after 100% - Just curious. I restore databases very often as I am a developer. Some of them has a size, that means that it takes some time. I use to backup with the same version as I restore from. I am aware, that if i restore a SQL 2012 with a SQL 2019, the converting takes some […] |
SQL Server 2019 - Development |
Trying to use rowversion (Timestamp) in SSIS as a for a high watermark - Trying to use rowversion (Timestamp) in SSIS as a for a high watermark to extract changed data Failure 1: try to store the Max Rowversion in a variable Varbinary(8) to Variable type Byte Get me this error. " failed with the following error: "Input string was not in a correct format.". Possible failure reasons: Problems […] |
Amazon AWS and other cloud vendors |
AWS Reserved Instance for Old Servers - We have a couple of SQL server instances(i2 and r3) from about 5 years ago. We are looking to reserve the instances now without upgrading to new, but I don't see any of these instances listed in the "Reserved Instance" section. In other words, the instances are not there to be purchased. I got to […] |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Laden...
Laden...
© 2024