By ronen ariely on
18/02/2023 05:38
When creating a VIEW using SQL Server Management studio (SSMS) wizard, then you might encounter the error: The ORDER BY clause is used only to determine the rows that are returned by the TOP clause in the view definition. This error is is NOT from the SQL Server but from the SSMS application. In this post I will elaborate a bit more, demonstrate the issue and explain the meaning of the message. There is no need to solve anything in most cases and it's just a warning for the user.
|
By ronen ariely on
19/11/2021 11:39
SQL Server 2022 is almost here. During the Microsoft ignite 2021 conference, on November 3, Microsoft announced the new version and started to present the new features and abilities. If you are working with SQL Server then it is now time to focus on SQL Server 2022. Read more on how to Get start with SQL Server 2022 - list of links
|
By ronen ariely on
05/11/2021 00:00
New as of today! Microsoft improved the function STRING_SPLIT and added a new optional parameter name: enable_ordinal, which allows us to get the returned SET in an order guaranteed, according to each substring's position in the input string
|
By ronen ariely on
23/04/2021 11:39
This post come to answer the question how to learn SQL, which raise in the forum from time to time. It brings my personal insights about self-learning and a few sentences on how to start learning SQL. It is not exactly a regular post like I usually write but since the question was asked once more yesterday then I simply copy the answer which I gave in the forum so I will have it documented for the next time it will be asked
|
By ronen ariely on
25/03/2021 21:04
Structured Query Language (SQL) commands can be categorize into DCL (Data Control Language), TCL (Transaction Control Language), DDL (Data Definition Language), DML (Data Manipulation Language), DQL (Data Query Language). So, what these terms actually means and how this is related to the way you should raise questions when you ask for help?
|
By ronen ariely on
08/06/2020 05:02
Let's "play" with some data and let me show how to use SQL Server to Analyze the Coronavirus Covid-19 data. The source of the data was taken from the CSSEGISandData GitHub project. In this post I will add some useful queries and explain how to use the data and what can we do with it.
|
By ronen ariely on
11/04/2020 01:41
Execute a job from inside another job is a simple task like executing any query. We simply need to start the external Job using the built-in stored procedure msdb.dbo.sp_start_job. Unfortunately if we have multiple jobs which needed to be executed in specific order Synchronously (meaning that only when one job end then the next one start), is a more complex task using the built-in SQL Server Agent. In this post I will mentioned several options to solve this task.
|
By ronen ariely on
07/04/2020 01:40
Let's assume that we have two databases A and B and we want to swap the names so the old database A will become B and the old database B will become A. In first glance you might think that you can simply backup both databases and restore database A with the name B and restore database B with the name A. This solution for swat two databases was presented in the MSDN forum. In this post I explain why this is not so simple and demonstrate one of the problematic issue in swapping databases this way.
|
By ronen ariely on
29/09/2019 07:36
OPENJSON is a build-in SQL Server table-valued function (return tabular structure), which parse text that formatted as JSON. By default, the function only parse the first level of the JSON document, but using explicit path to the nodes in the document we can parse the entire document including unlimited level of hierarchy. This sound great except the fact that JSON document is commonly used for unstructured data, meaning we do not know what nodes the document will have and what is the the path to each node... OPENJSON does not provide a dynamic parsing for hierarchy structure.
In this blog, I will present a simple recursive table-valued function, which based on OPENJSON and provide full dynamic hierarchy parsing of JSON document.
|
By ronen ariely on
07/08/2019 04:38
This post includes sample code for step by step: (1) create database. (2) CREATE TABLE. (3) create folder for the Audit logs. (4) CREATE SERVER AUDIT. (5) CREATE SERVER AUDIT SPECIFICATION. (6) CREATE DATABASE AUDIT SPECIFICATION. (7) Read the log file.
|
By ronen ariely on
21/06/2019 09:49
Error: The UTC time represented when the offset is applied must be between year 0 and 10,000.
A question in the MSDN forum about an error message which the user get, turned out to be an unknown (until now) bug in the SQL Server Management Studio SSMS (relevant to SSMS 18.1 and before).
If you are in Israel then you are probably fine😃, in fact anyone who use UTC/GMT Time Zone or positive offset in time (Meaning, location east to Greenwich England) is fine... But if you are in US for example, then you must know about this
Read more...
|
By ronen ariely on
30/03/2019 23:59
We have a SET of separated slots/ranges and we want to represent the merged ranges which cover all the separated ranges, using a SET of minimum number of ranges. In other words, we want to to Group continuous and overlaps Ranges together. If we have SET of slots/ranges, and two or more of these ranges has shared point/s (a point which exists in both ranges), then these ranges can be merge together into a single range.
For example if we are dealing with ranges of integers and we have the ranges 3-6 and 5-8, then we can marge these into the single range 3-8, or the ranges 2-4,4-6 can be merged into 2-6.
In my previous post I covered the solution using the "Gaps and Islands" approach. In this post I will cover a solution which is based on SQL Server built-in GEOMETRY data type.
|
By ronen ariely on
25/03/2019 13:19
Note! This post is draft, which I post fast as answer to question which asked at stackoverflow. Since I don't have time this week to prepare a well formatted post with images, full explanation, and well formatted text, but at the same time I want to provide a solution for the sake of these who asked for it, therefore I publish this as a first draft and provide the code for one of two solutions I will discuss.
Note! The solution which presented here is not the one which I recommend to use in this case. This solution address the question using a well known approach named "Gaps and Islands" and might fit for most cases. In my next post I will present a totally different approach using my personal trick, which can improve performance dramatically in some scenario.
So what do we have here? The post include code and some comments to solve several scenario of Grouping continuous Ranges together.
I will start with the simplest case which is ranges of integers, for example 2-4, 6-8, 8-10, 13-14 which should be grouped into 2-4, 6-10, 13-14.
Next I will move to explain issue related to the resolution of space between the ranges, and I will go to present a solution for Ranges of Decimal numbers.
Finally, using the solution which I presented in detail for INTEGERS I will present a solution for "Grouping continuous time-slots together", which was the original question in the forum.
|
By ronen ariely on
20/03/2019 22:40
This post summarize my lecture from last week at PASS DBA Virtual Group.
Understanding what we have under the hood is not only done for the sake of learning a theory, but it directly impacts your daily work, and it can help us to improve performance and reduce resources dramatically.
During this session we discussed the structure of tables behind the scenes. We saw the changes behind the scenes related to DDL actions, which we execute on tables. Using this information, I demonstrated several real case scenarios, and the dramatic impact of understanding the internals on choosing our solution.
Is the order of columns important? Is dropping a column is the right solution and what is the impact? Questions like those are very common in the forums and usually does not get the right answers even by experts, but the answers might be a game changer in production environment.
This session is a live demo!
There is no presentation to share, but in this post I will share the code and some points.
THIS POST DOES NOT REPLACE THE SESSION BUT COMES TO SUMMERTIME IT
It is highly recommended to watch the recording first
|
By ronen ariely on
28/11/2018 19:44
A common question that raise in forums: Is The Order of columns important?
We focus on the database's side and not the client's side point-of-view. For example, is order of columns related to performance, is it related to errors that might rise only when use specific order, or will SELECT query return different DATA (not important the order of the result SET but the DATA) if the order of columns is different...
In this post I want to present some simple demo which answer the question
Update 2019-03-21: adding example from my last lecture.
|
By ronen ariely on
25/09/2018 08:24
PowerShell gives us a powerfull tool to invoke queries using the cmdlet command "Invoke-Sqlcmd".
Invoke-Sqlcmd execute statements which are supported by the SQL Server SQLCMD utility, which is where the name Invoke-Sqlcmd came from probably. It allows us to execute Transact-SQL or XQuery statements, or sqlcmd commands. Using the parameter "-Query" we can execute inline queries, and using the parameter "-inputfile" we can specifies a path to a file, which is used as the query input to this cmdlet.
There are a lot of tutorials online on how to use Invoke-Sqlcmd command, which usually focus on the built-in paramatres and how to execute the command. One of these parameters is "Out-File", which allows us to send the output of the queries to a file, but how can we control the output of PRINT for example or the output of ERROR massage?!?
Today I want to discuss some undocumented options of using Invoke-Sqlcmd. In this post I will show how we can control the target of the output not only of the queries but also errors and user-defined messages (PRINT statements), and how we can send these to a new file, to the shell screen or to any other target.
|
By ronen ariely on
10/04/2018 22:00
Seems like Microsoft papered their services to the new GDPR regulation, and as part of the preparation several weeks ago a new feature named “PRIVACY” was added to the MSDN and TechNet profile. This feature enables us to download the data that Microsoft stores about our activities! Unfortunately, the data that is given to us is not formatted in a readable way, but in one long line of text [*updated] (JSON FORMAT) which can be in the size of hundreds of megabytes. In this post, I show how to get our data, view the data in raw format (JSON) and in readable format, and I gave queries to parse all the data into tabular structure using the built-in JSON features in SQL Server.
* Update 2018-04-17: I added Microsoft team's feedback and future plan, accordingly my post...
|
By ronen ariely on
20/03/2018 14:57
Seems like there is a confusion regarding the meaning of the style parameter in CONVERT function, and the way SQL Server use it. This short post based on a question that raise in the MSDN forum, and I will try to bring some insights here.
|
By ronen ariely on
10/03/2018 04:43
When we are working with Many-To-Many relationship between two entity tables, we often need to find all the entities (rows in one table) which have relations with specific list of entities from the second type (rows in the second entity table). Our goal is to get all the Users that related to all specific roles. For example, all the users that have both RoleId 2 and RoleId 4.
|
By ronen ariely on
17/02/2018 05:24
let me summarize the new features which were added to SQL Server Management Studio (SSMS) version 17.5
|
By ronen ariely on
09/02/2018 12:56
חדש!!! שירות מופע מנוהל של שרתי SQL באזור (Azure SQL Managed Instance ), הוא שירות חדש ששוחרר היום ל Public Preview וזמין לשימוש.
|
By ronen ariely on
19/01/2018 06:36
According to the documentation “ReadOnly lock on a SQL Database prevents you from deleting or modifying the database”, but in fact this is not accurate!
* Everything that I write about was tested at the time I write the post, and might be changed in the future!Let’s test it!
|
By ronen ariely on
23/11/2017 10:22
This is a simple Step-By-Step tutorial, showing how to use Azure BLOB Storage services to store backups of SQL Server databases. During the tutorial I will start with creating a new Azure Storage Account, next I will create new Credential in our local SQL Server and using the Credential I will backup and restore the SQL Server database.
|
By ronen ariely on
10/06/2017 04:23
This is short post I publish as an answer to a question in the MSDN forum. In this post I will go very fast on the theoretical topic and will move to a short demo. Relational database system implements relations by using foreign key, which point to the related unique key identifying the row in the other table (named Primary Key). Since foreign key can only point to a single row in the other table, this model cannot implement a direct Many-To-Many relationship between rows in two entity tables. Read more to see how we implement it...
|
By ronen ariely on
12/03/2017 00:00
Please to post a nice certificate I got from the India Mentor communities leader...
|
By ronen ariely on
10/12/2016 07:42
SET IDENTITY_INSERT doesn't work with 4 parts name, and as such it doesn't work with linked servers unless you execute dynamic SQL. Moreover, "SET IDENTITY_INSERT" is a session level setting, therefore when you connect to another server the setting of current session are not relevant. In this short blog I will show how we can use SET IDENTITY_INSERT on linked server using dynamic SQL.
|
By ronen ariely on
02/10/2016 06:30
* This post base on a question asked at the MSDN forums in this link.
In order to restore the database in the same instance with the original database, we need to (1) move the restored database files to new location, since two files cannot have the same path in windows operating system. (2) we must change the DIRECTORY_NAME for the Filetable data, since it is instance level element and it must be unique in this SQL Server instance.
We can configure the new path for the restored files using simple command "restore... with move <original path> to <new path>" for each file, but there is no built-in option to configure the DIRECTORY_NAME at the same time during restore. Well... In this post I will show step by step a simple procedure to restore the database as a new database on the same instance as the original database.
|
By ronen ariely on
09/07/2016 19:54
One of the new security features that SQL Server version 2016 brings, is the Dynamic Data Masking (DDM). Implementing DDM internally in SQL Server, aims to bring us better security, in the user level rules. User not been granted permission "UNMASK", cannot be exposed the original value, if column configured to be masked. Is this actually works?!? In this blog I will show how easy it is to expose the masked data, by any user.
|
By ronen ariely on
23/06/2016 23:25
When you try to open the Help Viewer from SSMS 2016, there are two behaviors that people reports about: (1) Instead of getting the new Help Viewer version 2.2, which came with the SSMS 2016, the old version 1.1 is opened. (2) Instead of getting any help viewer, the browser opened and redirects us to the Book-Online, or An error raises with the message "no app are installed to open this type of link (ms-xhelp)".
In one of my previous blogs I wrote about how to install Microsoft SQL Server 2016 Book-online for offline use. I mentioned this bug regarding starting the help viewer:
The current version is SSMS June 2016 generally available release, which mean that this version theoretically ready for production. Yet, the bug is still there, and it is time to focus a bit more on what seems to behave wrong, and how we can workaround these issues...
|
By ronen ariely on
19/06/2016 04:47
Text strings are created from characters. A collection of characters called a "character set". A character set, also known as a code-page or charset. It is an ordered set of characters in which each character is mapped to a numeric index, called a "code-point".
Character Encoding is the mechanism to map the code points into bytes. The code points are stored in the computer as one or more bytes (collation of 0 and 1). The visual representation of characters is configured by the font. A font is a collection of glyph definitions used to display characters...
|
By ronen ariely on
14/06/2016 08:05
Row-Level Security enables customers to control access to rows in a database table. Access to row-level data in a table is restricted by security predicate, defined as an inline table-valued function. The function is then invoked and enforced by a security policy.
According to the BOL, RLS filter predicates are functionally equivalent to appending a WHERE clause. The predicate can be as sophisticated as business practices dictate, or the clause can be as simple as WHERE TenantId = 42. Is this accurate?
|
By ronen ariely on
15/04/2016 12:45
background
At the beginning of the month I lectured at the SQLSaturday # 481 event about the new support of JSON in SQL Server 2016. During the demonstration I showed queries that returns JSON text. SQL Server returns the JSON text formatted as compact text / dense format (one line, no extra space), which is good for most cases that we want to store the text or pass it between machines for example. But, by using a compact format the structure of the JSON document is not readable.
In NoSQL servers, which based on JSON, we usually have a built-in method to format the JSON document into a format that is easier for humans to read (for example in mongoDB it named "pretty"). This feature must be added to the SSMS or to the SQL Server, in my opinion. In the mean time, for the sake of the lecture, I created simple app that do the job. it is basically a "one line app" using the nuget package Json.NET (Newtonsoft.Json).
After I uploaded the lecture materials (code and presentation), I got requests to upload the application as well. Since I do not like the idea that people execute code without understanding it, and since this is very simple and short code, and most DBA does not develop dot.net application, therefore I decided to post the code, as a step-by-step tutorial for beginners.
|
By ronen ariely on
29/02/2016 21:57
Most people heard about the 2000 year bug, which occur once in 1000 years, but less people familiar with much more common bugs related to February 29, which occur approximately every 4 years. Let's named these as the "February 29 bug" or the "Leap year bug".
This blog based on a message posted at MSDN forum, by Yaniv Cohen, who notice that the use of the function ISNULL returns unexpected result, regarding February 29. Is this really unexpected result and we found a BUG?!? Starting with the original issue, as a starting point, I explain how the relevant functions behaves behind the scenes, and the difference between them. I reproduces the "unexpected behavior" using simpler case, and point to the source of the "unexpected behavior". I will present demos that you can execute in order to figure out how the relevant functions works, and in particular gives you the tools to understand the extent of the problem.
|
By ronen ariely on
14/12/2015 10:38
I see in the forum this question raised all the time, and yet the solution that people get usually based on looping and complex math, while there is a simple and much better solution as shown in this code. In this short blog I will wrote a simple and VERY fast solution to convert Decimal number to Binary number, Decimal number to Hexadecimal number, and vise versa without using any loop. My solution for binary base is based on using BITWISE.
|
By ronen ariely on
06/09/2015 14:03
Bitwise Operators performs "wise" "bit by bit" manipulations between two expressions of types integers or binaries (binary, bit, int, smallint, tinyint, varbinary, bigint). There are three Bitwise Operators in T-SQL which includes: & (Bitwise AND), | (Bitwise OR), ^ (Bitwise Exclusive OR). In this short post we will explain the behavior of each of these operators by following a simple practical examples.
** This post include several accessories, which you can use in other cases. For example A function to convert integers base ten number into base two number (without using any direct loop).
|
By ronen ariely on
25/05/2015 13:10
In some cases the SQL Server query optimizer engine fail to build the best execution plan. This is the place where our abilities as DBAs can be handles. One of these cases is when we are using windows functions like ROW_NUMBER, which use "ORDER BY" the clustered index. Since our data is already sorted by the clustered index, there is no reason to sort the data again. In simple query the SQL Server query optimizer "understand" it, but in more complex queries it might fail. In this short post, I will show a small trick to improve our query and make sure that the windows function do not waist resource on sorting the data.
|
By ronen ariely on
07/05/2015 14:17
In this blog I will show step by step how I examined the DateTime2 data, in order to find the actual storing format. The basic process is based on reverse engineer by examining the binary data that we get in CONVERT to VARBINARY(16)
-- check the data as binary show us the format behind the scenes:
DECLARE @d DATETIME2 = '2016-02-27 00:00:00.000' -- My next birthday :-)
SELECT CONVERT (VARBINARY(16),@d)
GO
* Result: 0x070000000000143B0B
The goals in this blog are: (1) understand how DateTime2 stored in the database, (2) to provide a small glimpse on the process that we can use in order to examine what is going behind the scenes in the Page Data File (for specific data type).
|
By ronen ariely on
04/05/2015 17:36
There is a common confusion regarding "displaying format" and "storing format" of dates types. We can find lot of questions in the forums regarding "storing format" of dates, which are actually regarding the "displaying format", in external application.
For example questions like: I am getting the error “DateTime data type resulted in an out-of-range value”, or questions like: “how can I change the DateTime column format in the database”.
In this post I will I will focus on SQL DateTime type. I will organizes the issue using the different terms, and I will give some basic solutions for common issues.
|
By ronen ariely on
20/03/2015 01:08
Good day, and welcome to the TechNet wiki summit 2015.
This is how I opened my lecture yesterday…
This simple sentence is very meaningful! It hides so much in two words. Usually when I start a lecture I open with “Good morning” or Good evening” or something that make sense to the current audience at the current time in the current place. In this case, our event appeals to variety audience which engage with variety technologies, from all over the world in different time-zones. In my opinion this is the main feature of the TechNet WIKI summit.
|
By ronen ariely on
05/03/2015 20:48
אני רוצה להזמין את כולם לכנס העולמי של קהילת TechNet WIKI הנערך בעוד כמה ימים, בתאריכים 17-18-19 החודש (מרץ). הכנס מועבר באינטרנט Online , וכמובן אינו כרוך בתשלום. בכנס יועברו הרצאות ודיונים שונים על ידי כ-30 מרצים מכל רחבי העולם שנבחרו על ידי מיקרוסופט.
אני שמח להמנות על המרצים בכנס , ואני מאוד אשמח לראות את חברי הקבוצה, מגיעים להרצאה שלי :-)
ההרצאה שלי תערך ביום רביעי 18 לחודש בשעה 19:45 לפי שעון ישראל (שינויים ופרטים נוספים אני אפרסם בעמד הפייסבוק שלי).
ניתן להירשם כאן!
|
By ronen ariely on
28/11/2014 13:46
Split Date's Range into Shifts per days
|
By ronen ariely on
17/10/2014 10:27
Sometimes A new version or feature release and a new bug which related to this feature revealed, but sometimes we stuck with a BUG for years.. many years... 15 years even... will it be fix in the next version? Using User Defined Function In Constraint can lead to a BUG! In this short blog I will just reproduce the BUG and show a simple workaround. This is not a new topic, and you probably can find lot of articles on net,on the same issue, but since it came up again... i decided to post this blog again.
|
By ronen ariely on
10/10/2014 00:36
Short and simple Stored Procedure to find the pearson who was the last one who deleted a record from a table. Very useful when your boss delete row and start to shout at you why the data is not accurate, or why tour application have a bug :-)
|
By ronen ariely on
01/10/2014 10:53
This is small set of script in order to get the connection properties. You can use it in order to compare two execution of the same query on the same database which use different Execution Plan as a result of different Connection Properties.
|
By ronen ariely on
11/09/2014 12:01
This short blog give a simple example how to use "FOR XML" hint in order to consolidate data in different rows into a single row in the result SET (an operation known as Un-Split data). In this example we are going to group together only rows with the same value in specific column/s. In short we can call this action "Un-split data with grouping". This post was updated on July 25 2018 in order to add a solution using STRING_AGG function which was added in SQL Server 2017.
|
By ronen ariely on
04/09/2014 09:41
SQL Server can listen to request which come to specific IP address on specific port, or to all request regardless the IP, It can listen to request which come to a Named pipe, as well. By default, SQL server uses port 1433 in TCP/IP, and default instance of Microsoft SQL Server listens on "\\.\pipe\sql\query" named pipe.
In this short article I will show how we can configure those options.
|
By ronen ariely on
17/08/2014 19:11
לפני כמה ימים נשאלה שאלה מעניינת בפורום של MSDN העולמי (אנגלית). לאחר דיון קצר בפרוום ובפייסבוק נראה שהדיון גווע עם האמירה "אי אפשר". מי שמכיר אותי יודע שאמירה כזו במחשבים לא מקובלת עלי ולמעשה הגעתי לשרשור של ההודעה בדיוק בנקודה זו. לכן החלטתי למצוא דרך פשוטה לפתרון הבעיה. בלוג זה מציג את הרעיון העומד מאחורי הפתרון בצורה מפורטת.
אז מה הבעיה מולה אנחנו עומדים?
שימוש ב DBCC כחלק משאילתת VIEW לא מאפשר בצורה ישירה. אז כיצד אפשר לבצע את זה בכל זאת?
בואו נראה עד כמה הדברים קלים לביצוע :-)
קריאה מהנה...
|
By ronen ariely on
26/07/2014 23:21
רמת בידוד סדרתיות (Serializable) דורשת כי כל שאילתה שבוצעה במהלך עסקה חייבת לקבל את אותו הסט של שורות בכל פעם שהיא מתבצעת במהלך העסקה. נעילת טווח נועדה להגן על שורות אשר בצורה עקיפה או ישירה נמצאות באוסף השורות שנקראות על ידי הוראת שאילתה, בזמן שאנחנו עובדים ברמת בידוד סדרתית. נעילת טווח מפתח (key) מבטיחה לנו שמירת הדרישות של רמת הבידוד, על ידי מניעת שינויים במפתחות אשר עלולים להיות בטווח המפתחות שהשאילתה קוראת.
במאמר מעמיק זה נדון בנושא נעילות טווח והקשר לרמת בידוד סדרתית. כמו כן נציג מקרים בהם נוכל למטב את השאילתה ולמצנוע נעילות תוך שינוי קטן בשאילתה, ובכך נוכל להשיג את מיטוב העבודה.
|
By ronen ariely on
15/07/2014 20:56
הקדמה
במשפט אחד נוכל להתייחס לחותמת זמן (timestamp) כסוג של תאריך, שמנוהל ברמת מסד הנתונים ונשמר בצורה בינארית. חותמת הזמן נועדה לאפשר לנו לנטר את השינויים של נתונים בטבלה. הרעיון הוא להצמיד לכל שורה בטבלה חותמת זמן, שמתאימה לזמן השינוי האחרון שנעשה בשורה זו. שינוי זה יכול להיות תוצאה של הכנסת השורה לטבלה, או עדכון שלה.
על מנת לעמוד במטרות של טור זה, השרת חייב להבטיח שהערכים בחותמת הזמן יהיו תמיד ייחודיים, בין שני זמנים שונים.
שרתי SQL נועדו לעבודה מסיבית עם נתונים הן מבחינת כמות הנתונים והן מבחינת מהירות העבודה עם הנתונים. השימוש בגדלים מוחלטים כגון סוגי זמנים שונים, לא נותן לנו את הפתרון המתאים בשל תלות ברזולוציה של הנתונים, כפי שנראה בהמשך. כחלק מהצורך לניהול נתונים במערכות כבדות נמצא פתרון בעזרת סוג שונה, שקיבל את השם חותמת זמן - timestamp.
במאמר זה אני אנסה לתת הסבר מקיף ומלא על נושא חותמות זמן בשרתי SQL Server החל מהגרסאות הקדומות שלו ועד השרתים החדשים.
|
By ronen ariely on
30/05/2014 08:36
Buffer Pool Extension או בשם המקוצר BPE היא תוספת חדשה בגרסאות Standard ו Enterprise של SQL Server 64 Bit. באופן תיאורטי הרחבה זו יכולה לשפר באופן משמעותי את היכולת של מערכות הצורכות זיכרון כגון OLTP. ההרחבה מבוססת על הוספת Buffer Pool היושב על מחיצה מהירה (SSD למשל), ובכך מאפשרת להרחיב את השימוש בזיכרון RAM. ה BPE יראה עבור המשתמש כזיכרון מטמון נוסף. רכיב בשם Buffer Pool Manager אחראי על ניהול המידע בזיכרון המטמון המורחב (תיאום בין ה RAM לבין ההרחבה). ההרחבה נעשית על ידי יצירת מטמון זיכרון הירארכי, כאשר הרמה העליונה מתקיימת ב RAM והרמה השנייה בהרחבה של הזיכרון המטמון.
|
By ronen ariely on
28/04/2014 13:10
In this short blog I will post a simple dynamic query to search in one operation all string columns ('text','ntext','varchar','nvarchar','char','nchar') of the specific table or in all tables of the database. Next step, we can use CROSS APPLY and SPLIT Function (or user type) in order to expand this query to get result from several searching strings.
|
By ronen ariely on
09/04/2014 20:46
לפני כמה חודשים העליתי מאמר בנושא הרצת אותה שאילתה דרך אפליקציות שונות. במאמר הקודם, ראינו שהשרת בונה תכנית הרצה שונה לחלוטין לפעמים לאותה שאילתה כאשר היא מורצת דרך תוכנת ה SSMS וכאשר היא מורצת דרך אפליקציית Dot.Net למשל. אם נרצה לסכם את המאמר לשורה אחת אז נוכל להגיד שמקור ההבדל נובע מהגדרות שונות של ה SESSION וההתחברות אל מסד הנתונים והשרת. במאמר זה נדון בנושא הנשמע דומה דומה אבל עם הסבר שונה לחלוטין: הרצת אותה שאילתה בגרסאות שונות של שrת ה SQL. אפשר לנחש מהעובדה שאני כותב בלוג זה שככל הנראה, שגרסאות שונות יתנהגו באופן שונה.
|
By ronen ariely on
11/01/2014 19:04
Sub Queries is not permitted in Check Constraint. we will show how to bypass this restriction.
|
By ronen ariely on
07/01/2014 13:21
Volume Shadow Copy Service (עותק צל) הוא שם של קבוצת ממשקים (interface) מסוג COM interfaces. רכיבי COM אלו מיישמים סביבת הרצה שמאפשרת לבצע גיבויים בזמן שיישומים במערכת ממשיכים לכתוב לאמצעי האחסון ונועלים חלק מהקבצים. במערכות הפעלה של מייקרוסופט VSS נתמך מגרסת XP והלאה. במערכות מבוססות NT אמצעי האחסון מנוהלים על ידי ה Disk Management MMC snap-in. מאחורי הקלעים תוכנה זו עושה שימוש ברכיבי ה VSS.
הליך של ביצוע עותק צל לא יעבוד טוב אם בזמן ביצוע ההעתקה, יבוצעו קריאות לשינויים בקבצים אשר לא ינוהלו בצורה מתאימה לאפליקציות העובדות עם הקבצים. בגרסת SQL 2005 מייקרוסופט סיפקה לנו תמיכה לביצוע עותק צל על ידי כך שסיפקה כתבן (VSS writer) מתאים בשם SqlServerWriter.
במאמר זה נסביר בצורה כללית מהו עותק צל (VSS) וכיצד הוא עובד; נראה בקצרה כיצד עובדים עם תוכנת הניהול VssAdmin ליצירה, מחיקה וקריאה של עותקי צל במערכת ההפעלה; נראה את הקשר והחשיבות לשרתי SQL; נשים דגש על החלק המעשי כאשר נציג כיצד הדברים עובדים עם קבצי SQL. נראה כיצד אפשר לפתח אפליקציה קטנה להעתקת קבצי SQL תוך כמה דקות של עבודה. אפליקציה זו תאפשר לנו להעתיק קבצים ללא הרצת שאילתת גיבוי וללא צורך בביצוע פעולת detach והורדת מסד הנתונים מהאוויר.
|
By ronen ariely on
11/12/2013 03:03
Hierarchical data is organized into a tree-like structure. The structure allows representing information using parent/child relationships: each parent can have many children, but each child has no more than one parent (one-to-many relationship). Our records have a unique column (named "ID" in our case). Parents and children are tied together by "pointer" column. In our case we will call our pointer column "ParentID".
Our requirement is to sort the data which is based on the Child-Parent hierarchy according to the tree structure. Each child must be under its parent tree, and all children with the same father, sorted by their ID order (on Appendix A we will show how to sort by any other column).
|
By ronen ariely on
25/11/2013 18:56
SQL Random String using CLR
|
By ronen ariely on
28/10/2013 16:44
I see many questions about the difference between Cursor and While Loop in SQL queries. I think this is a fundamental mistake to compare them at all. It's like comparing a car and a boat. We use the car moving on land, and we use a boat to travel at sea. I would not recommend anyone to try the opposite. So what's so confusing?
Let's try to have a brief discussion about "Cursors and Loops" in general and the replacing between them (yes we can car to travel at sea and a boat to move on land).
|
By ronen ariely on
24/10/2013 15:21
In the last few weeks we are all talking about the upcoming next version of SQL Server 2014. In the process to the final release, Microsoft give us the CTP beta versions, which release with poor documentation. The second best feature I loved on the SQL 2014 (after the In-Memory OLTP) is by sure the new "extremely useful" DMV: sys.dm_exec_query_profiles. This DMV did not work on CTP1, and I understood that it should be ready on CTP2.
Is it working, and is it extremely useful as expected?!?
Let's play with it a bit
|
By ronen ariely on
20/10/2013 06:40
שרת ה SQL מנהל את קובץ הלוג הפיסי ביחידות וירטואליות הנקראות Virtual Log File או בקיצור VLF.
* בלוג קצר זה מהווה רק הפתיחה להרצאה שלי בנושא זה ויכול לתת את נקודת ההתחלה בלימוד.
|
By ronen ariely on
16/10/2013 18:41
קדימה להורדות אנשים ובלי תירוצים! גרסת הבטא החדשה יצאה לאור אז אם אתם רוצים להוביל זה הזמן לגשת ולהתחיל לבדוק את האפשריות החדשות. קדימה... תהיו הראשונים לכתוב את הבלוגים הבאים על מה שעוד לא נכתב.
|
By ronen ariely on
13/10/2013 19:11
שאילתות DML עושות שימוש מאחורי הקלעים ב 2 טבלאות: inserted וכן deleted. שרתי SQL מייצרים טבלאות אלו on-the-fly ומנהלים אותן. אלו טבלאות היושבות בזיכרון (memory-resident tables). משך החיים של טבלאות אלו הוא הטרנזקציה.
נראה בקצרה את השמוש בטבלאות אלו.
|
By ronen ariely on
25/09/2013 09:44
למי שלא יודע אז קבוצת המשתמשים של SQL בישראל היא חלק מארגון PASS וכל החברים הרשומים בקבוצה יכולים לקחת חלק בהצבעה. הקבוצה הישראלית נפגשת אחת לחודש במשרדי מייקרוסופט, שם מועברות הרצאות על ידי מיטב אנשי המקצוע בשוק...
לקחת חלק בבחירות זה התנאי הראשון כדי לקבל את הזכות להתלונן! זה נכון לבחירות לכנסת, לערייה או לעמותה בה אתם חברים. מה גם שזו דרך טובה לנסות להשפיע ולו במעט על הכיוון המתאים לכם. זו היזדמנות לבחור את המועמד שלכם.
נחזור לנושא הבחירות. אחד המועמדים הפעם הוא עמי לוין (Ami Levin) שהיה האחראי על קבוצת המשתמשים בישראל כ 8 שנים, עד שעזב את הארץ לטובת עבודה בארה"ב, שם הוא מבלה את השנה האחרונה. זאת הזדמנות לתמוך בנציג במועצת המנהלים של PASS, אשר יוכל לייצג אותנו ולפעול למעננו.
|
By ronen ariely on
22/09/2013 03:55
In this short blog I will show how easy it is to add sequence's column to an existing table which already have data. Sequence is a new element added to SQL server 2012 (and can be find in MySQL and Oracle for a very long long… long time) for implementing automatically assigned integer values. We can even assign a sequence to an existing integer column which already have values in it, in a direct simple query (not like an Identity column).
|
By ronen ariely on
20/09/2013 07:51
short and simple way to dynamically use bulk insert to import data from all files in specific folder.
|
By ronen ariely on
15/09/2013 16:32
Some report generated by third party application export data which do have a consistent format. Each line come in different format. Those application use an export's format that design on-the-fly, for each record and each value in the record separately. The format is set by the value itself.
For example if there is data in the field then it will export the data inside a quotation mark, but if there is no data then the data will be blank and without a quotation mark. Moreover some application do not use 'data type' when generating a report. If there is data and the data fit as numeric then again some applications might not use any quotation mark and in the same field on different record a data that do not fit as numeric will be export in quotation mark. We can think about a single CSV file which a specific column is exporting in 6 different formats. In order to use bulk insert directly we have to make sure that all the data is consistent with one format. So how do we do it?!?
|
By ronen ariely on
08/09/2013 10:16
RAND / NewID and some more build in function have a side-effecting, and cannot be used directly in a UDF. One of the workaround is to create a View and your own UDF as random function
|
By ronen ariely on
08/09/2013 08:42
Microsoft SQL Server 2005 introduces the max specifier. This specifier expands the storage capabilities of the varchar, nvarchar, and varbinary data types. Before SQL Server 2005 we used ntext , text, and image data types.
At this time SQL Server 2012 still support those types, But the SSMS GUI does not fully support it!
|
By ronen ariely on
10/07/2013 22:56
Case Study:
We need to restore a database which original file size was 100GB. Our disks on the target computer hold 80GB. We know that the database can be shrink to less than 80GB. The problem is that restore operation always restores the files to the same sizes they were before the backed up. There is currently no build-in way to "restore with shrink". But… There is always a BUT :-)
|
By ronen ariely on
04/07/2013 09:29
במדריך קצר אני אראה כיצד אנחנו יכולים להכין אלמנט CLR בשרת SQL ולהחזיק פרמטר של ה CLR בזיכרון לשימוש משותף של כל הפניות ל CLR. לשם הדוגמה נכין פונקציה קטנה של COUNT. הפונקציה תשמש לנו לספור כמה פעמים פנו אל ה CLR שלנו מהרגע שהשרת התחיל לעבוד. המורכבות היא כמובן לא בחלק של הפיתוח קוד בדוט-נט, כי אם קשור בהגדרות שונות בשרת ה SQL על מנת לאפשר להריץ את הקוד. על מנת לשתף פרמטר בין מופעים שונים של מחלקה ואיפוס הפרמטר שלנו עם ההרצה הראשונה של האלמנט, אנחנו נעשה שימוש בבנאי סטאטי (Static Constructors).
|
By ronen ariely on
26/05/2013 08:18
הדרך הפשוטה ביותר להעתיק משתמש משרת אחד לשרת אחר היא פשוט לייצר משתמש עם אותה ססמה ואותו שם, אבל האם זה יעבוד בצורה הפשוטה? האם אלו אכן העתקים של אותו משתמש? האם נוכל עתה להעתיק מסד נתונים למשל ולהיכנס אליו עם המתמש הזה שהיו לו הרשאות למסד הנתונים בשרת הקודם? כמובן שלא אחרת לא היה לי על מה לכתוב :-)
|
By ronen ariely on
06/04/2013 11:03
בהמשך לשאלה בפורומים שהעלתה דיון קצר, אני מעלה דוגמה פשוטה לפתרון הבעיה של מציאת רשומות רצופות המופיעות יותר ממספר פעמים מסויים שרוצים. החלק המרכזי בפתרון הוא משחקי מחשבה של אלגוריתמים על פונקציות חלון שונות על מנת שנוכל לדרג את הרשומות שלנו בהתאם לדרישות הבעיה. לאחר שהצלחנו לדרג את התוצאות כל מה שנשאר לנו זה לבחור את הרשומות המתאימות למספר ההחזרות שמחפשים.
בשלב זה מתוך מחסור בזמן אני מכניס את כל הבלוג לשאילתה אחת ארוכה בה ניתן למצוא את כל ההדרכה החל מ DDL+DML, שלבי המחשבה עד להגעה לפתרון וכמובן השאילתה הסופית. לאחר השאילתה הסופית הוספתי כמה נקודות קטנות למחשבה ודוגמה לשאילתה נוספת העונה לבעיה דומה בה אין לנו חשיבות לאחד הטורים כאשר אנחנו בודקים את הרציפות ז"א הרציפות נבדקת רק לפי חלק מהטורים.
|
By ronen ariely on
29/03/2013 15:08
בבלוג קצר זה אציג דרך יעילה למחיקת רשומות כפולות ללא מציאת הרשומות הכפולות תחילה (חלק זה כבר הצגתי בבלוג אחר) וכאשר אין לנו מפתח ראשי או אינדקס ייחודי שיכול לעזור לנו לקבוע מי הרשומה שאנו רוצים לשמור. אחת האפשרויות שאציג תעשה שמוש בפונקציה ROW_NUMBER על מנת למצוא כפילויות, ואפשרויות שנייה תתבסס על המיקום הפיזי של הרשומה ב page. מיקום זה הוא כמובן ייחודי מפני שכל רשומה נמצאת במיקום אחר.
* בלוג זה הוא דוגמה טובה לשימושים אפשריים בפרמטר פחות מוכר ושאין לו תמיכה רשמית, הקיים לכל רשומה בכל טבלה ונועד לשימושים פנימיים בעקרון. הכוונה למיקום הפיסי של הרשומה.
|
By ronen ariely on
28/03/2013 18:39
כניסה למצב המתנה הוא מצב בו טרנזקציה שנמצאת בהרצה נכנסת להשהיה (עצירה זמנית). אם אתם מריצים שאילתה שלפעמים רצה מהר ולפעמים נראה כאילו נתקעת למשך זמן רב אז ייתכן שהשאילתה (או בכללית הטרנזקציה המכילה אותה) נכנסה למצב המתנה. ישנן סיבות רבות שיכולות לגרור כניסה למצב המתנה, החל מפעולות אחרות על מסד הנתונים כמו שאילתות אחרות היוצרות נעילה על אותם נתונים, פעולות בשרת SQL עצמו שאינן קשורות ישירות במסד הנתונים הספציפי (ולכן אם אתם עובדים בשרת משותף ייתכן שאין לכם בכלל דרך לנטר את הנושא), ועד לסיבות שאינן קשורות בכלל לשרת כי אם לאפליקציות אחרות היושבות על המחשב ומשתתפות באותם משאבים.
|
By ronen ariely on
19/03/2013 18:22
A brief summary of the similarities and differences between 'PRIMARY KEY' and a 'Unique index'
|
By ronen ariely on
20/02/2013 20:05
COLUMNS_UPDATED היא פונקציה קטנה מובנית בשרתי SQL שנועדה לעבודה עם טריגרים (trigger). פונקציה זו מאפשרת לנו לזהות איזה טורים עודכנו או הוכנסו לטבלה (או לטבלה הוירטואלית VIEW).
העבודה עם הפונקציה קלה אבל הנתון שהיא מחזירה מחייב פיענוח וזה החלק המעניין. הפונקציה מחזירה ערך בודד מסוג varbinary הכולל את כל מספרי כל הטורים שעודכנו או הוכנסו.
|
By ronen ariely on
20/02/2013 19:50
MSDTC או DTC בקיצור הוא שירות קטן שרץ ברקע ומנהל את הטרנזקציות במערכת ההפעלה. MSDTC משמש לשרתי ה SQL כמו גם לכל אפליקציה אחרת על מנת לנהל טרנזקציות מבוזרות בין כמה מכונות. הרעיון הבסיסי הוא לנהל מצב לדוגמה בו אנחנו מתחילים טרנזקציה הפועלת על מכונה A ומבצעת כמה פעולות ואז נגשים למכונה B לבצע עוד כמה פעולות. אם הפעולות במכונה B נכשלו ולכן בוטלו (rollback) אז הפעולות במכונה A שכבר בוצעו יבוטלו גם כן
|
By ronen ariely on
08/01/2013 21:35
Activity Monitor is a new features and improvements in SQL Server 2008 Management Studio (SSMS). We can use Activity Monitor to obtain information about SQL Server processes and how these processes affect the current instance of SQL Server.
|
By ronen ariely on
08/01/2013 19:08
SSMA הוא כלי חינמי נתמך מבית מיקרוסופט המפשט את תהליך העברת נתונים ממסד נתונים אחרים שונים לשרתי SQL Server.
|
By ronen ariely on
30/12/2012 11:48
בהמשך לשאלה שנשאלה באחד הפורומים אני מעלה בלוג קצר זה בנושא מעניין מאוד לדעתי.
השאלה העומדת על הפרק היא כזו:
יש לנו שאילתה של SELECT פשוטה עם סינון לפי טור מסויים. נניח ID = 10000. כמו כן אנחנו רוצים לקחת את נתון זה כחלק מהנתונים החוזרים.
מה יהיה נכון יותר, לרשום את הערך בצורה מפורשת בחלק של ה SELECT או להישתמש בשם של הטור?
-- Using parameter VS using a fixed data
select id from QQ01 where id = 10000
select 10000 from QQ01 where id = 10000
* האם אין דרך שלישית טובה יותר?!? נראה דרך נוספת
|
By ronen ariely on
13/07/2012 11:58
לא אחת עלינו לעבוד עם נתון של תאריך בפורמט של שרשרת או הפוך. כאשר השרשרת שרוצים לקבל או ליצור היא בפורמט המוכר על ידי שרת ה SQL כפורמט של תאריך אנחנו יכולים לעבוד ישירות עם אחת מהפונקציות המובנות שיש לנו להמרה CONVERT או CAST. אבל אם מדובר בפורמט מעט שונה?
הערה: בשרת SQL בגרסה 2012 נוספה לנו פונקציה חדשה מבוססת על CLR בשם FORMAT. פונקציה זו יעילה מאוד (מבוססת כאמור על CLR) ובאפשרותה ניתן לבצע את כל שיש במדריך זה בעקרון. מדריך זה נועד לעבודה בגרסאות קודמות. עם זה כדי לא להשאיר את הדברים באוויר נראה בסופו של המדריך כיצד ניתן לעבוד עם גרסת 2012 ופונקצית FORMAT.
|
By ronen ariely on
29/06/2012 20:41
מעונינים לעבור לשרת חדש?
מה נעשה עם כל ההגדרות שיש לנו בשרת הישן? כיצד נזכור מה להעביר כדי לקבל עותק קרוב ככל הניתן לשרת הישן?
מסמך זה אינו מדריך במובן הרגיל (ייתכן שבהמשך אמשיך אותו יותר לעומק ואנסח בהתאם). כרגע אני מציג למעשה מסמך פנימי שכתבתי פעם לשמוש אישי לאור כך שנושא עלה באחד הפורומים. לפיכך לא מכוסים בו כל הנקודות כרגע. אבל אני מקווה שהוא מהווה נקודות התחלה יעילה ויעזור.
|
By ronen ariely on
26/06/2012 18:32
הפרמטר UNION משמש לנו לצורך איחוד שאילתות של שליפת נתונים. ז"א אם יש לנו 2 או יותר שאילתות (בלתי תלויות) מסוג SELECT אשר מחזירות רשומות, ואנו רוצים לאחד את התוצאות של שני השאילתות לתוצאה אחת המחזירה את כל הרשומות של כל אחת מהשאילתות שלנו, אז נוכל לעשות שימוש בפרמטר זה.
על מנת לחבר את השאילתות עלינו לעמוד בכמה כללים הגיוניים פשוטים אשר יאפשרו לנו להכניס את התוצאות של כל השאילתות למקבץ תוצאות אחד. אחרי הכל התוצאה המשולבת צריכה להתאים למבנה טבלאי בו לכל השורות יש מבנה זהה, גם אם מקור הנתונים היה שונה. מסדי נתונים שונים מתנהגים בצורה שונה במקרה של תבנית שונה החוזרת בכל אחת מתוצאות השאילתות אשר מנסים לאחד. יש כאלה שמחייבים תבנית זהה לחלוטין ויש מי שמאפשר סוגים שונים כל עוד ההמרה בינהם נתמכת.
בבלוג זה אני אדון בבעיות הקשורות ב UNION ובפתרונות
|
By ronen ariely on
26/06/2012 17:11
יצרתם טבלה זמנית בצורה דינאמית ועתה אתם רוצים לקבל אינפורמציה על הטורים השונים של הטבלה?
בבלוג קצר זה נציג שאילתה למציאת האינפורמציה של טורים בטבלה זמנית
|
By ronen ariely on
31/05/2012 08:35
אני מניח שהמצב הכי נפוץ בו יש לנו יחס בין טבלאות הוא יחס של יחיד לרבים. למשל יחס בין טבלה של שאלות וטבלה של התשובות לכל שאלה. מדובר על מצב בו לכל שאלה יכולות להיות מספר תשובות. נעזר בדוגמה זו על מנת להציג נושאים מתקדמים יותר שהועלו בפורום MSDN.
בבלוג זה נדון ביחסים בין טבלת שאלות וטבלת תשובות אפשריות. כאשר לכל שאלה ניתן להכניס מספר תשובות נכונות
החלק "המיוחד" בו נדון הוא דרישת הלקוח לקבוע לכל שאלה תשובה אחת כברירת המחדל.
הנושא עלה בדיון בפורום וקיבל כמה פתרונות מהירים בהתחלה. עם זה מכאן התחיל דיון יותר מעמיק על הפתרונות השונים. אני אציג בקצרה מאוד הערות שהועלו ואת הסיבה המרכזית לכך שהיה צורך במשהו אחר, וכמובן שאציג את הפתרונות שהצגתי בפורום בפירוט
|
By ronen ariely on
05/05/2012 22:31
בשפות פיתוח רבות אנו מכירים פונקציות בסגנון ISNUMBER. פונקציות שמקבלות ערך כלשהו ומחזירות ערך בוליאני העונה לשאלה האם הערך שבדקנו מתאים בפורמט שלו לערך של מספר. או האם ניתן להסב (CONVERT) את הערך לערך מספרי. ב SQL יש לנו פונקציה בשם ISNUMERIC עליה נדון במדריך קצר זה, כמו גם בפתרונות כאלה ואחרים עבור גרסאות קודמות של SQL.
* נקודת המוצא של מדריך זה היא שמטרתנו היא לבדוק אם ערך קסטואלי כלשהו נמצא בפורמט מספרי.
* נציין כבר בהקדמה שפונקצית ISNUMERIC לא בודקת האם ערך של שרשרת מסוימת הוא תואם למספר! אלא האם הערך תואם לערך נומרי!
טעות זו נפוצה גם אצל DBA-ים מנוסים והדבר מופיע גם בבלוגים שונים באינטרנט. הטעות בהבנה של מה עושה הפונקציה ומה הוא המושג נומרי, היא מקור לבלוגים המדווחים על באגים שיש בפונקציה ובתוצאות שהיא מחזירה או טענות לגבי הגיון לא נכון או לא מובן של הפונקציה בעוד הטעות היא בהבנת הפונקציה. בבלוג זה נדון בפונקציה המובנית בגרסת SQL 2012 וכן נציג פתרונות מתאימים יותר עבור בדיקה האם הערך שלנו הוא תואם למספר.
|
By ronen ariely on
05/04/2012 14:23
בהמשך לשאלה שהועלתה באחד הפורומים נדגים כיצד נוכל לקחת נתונים מלוג זמנים כלשהו בו נרשמים זמן התחלה וזמן סיום של אירוע כלשהו (למשל לוג זמני גלישה בחברת אינטרנט) ולהציג סיכום של זמן בכל חודש עבור כל סוג נתון מסוים (למשל עבור לקוח בנפרד).
בקריאה ראשונה ניתן לטעות ולחשוב שמדובר בפעולה מאוד פשוטה של GROUP BY על מספר הלקוח ועל החודש וסיימנו את כל התרגיל. אך מה אם הנתונים שנרשמו לנו בלוג ברשומה אחת משוכיים לכמה חודשים? במקרה זה יהיה עלינו לפרק תחילה את הזמן הכולל שנרשם ברשומה לפי החודשים
|
By ronen ariely on
20/03/2012 19:31
מדוע עבודה במסד הנתונים עם "מכלול הנתונים"* מהירה יותר מעבודה עם רשומות? * במדריך זה אני משתמש במושג "מכלול הנתונים" ברמת מסד הנתונים כשהכוונה להתייחסות לכל הנתונים כאלמנט אחד (למשל שימוש ב bulk insert או select into) בניגוד לעבודה עם הנתונים כאוסף של רשומות (insert into והכנסה של נתונים בזה אחר זה או אפילו כולם ביחד) נעבור על כמה נקודות כלליות הקשורות למסד הנתונים ונסביר את ההתנהגות השונה ברמת מסד הנתונים, וכן נעבור על דרכי המימוש בפיתוח בטכנולוגיית Dot.Net ועבודה עם Entity Framework בפרט.
|
By ronen ariely on
16/02/2012 07:56
הודעת שגיאה בקבצי הלוג של שרת ה SQL
בקריאה לפתרון מצב שקובץ הלוג (הכוונה לקובת לוג השגיאות ולא לוג של מסד נתונים) התמלא בקריאות, התברר לי כבר במבט ראשון שכל הודעות האזהרה והשגיאה מוכרות וידועות והפתרון בהתאם. בשבוע הקרוב אכתוב כמה בלוגים לגבי שגיאות נפוצות שנראות בקובץ הלוגים של שרת ה SQL. את הבלוג הראשון ברצף בלוגים זה ניתן לראות כאן. בעבר כתבתי כבר דיי הרבה בלוגים בנושא הודעות שגיאה. הכוונה כאן רק להוסיף ברצף כמה בלוגים בנושא זה על שגיאות שעדיין לא כיסתי בעבר. בלוגים נוספים בנושא שגיאות ניתן למצוא בחיפוש במערכת הבלוגים של האתר. בבלוג הנוכחי נדון בשגיאות הבאות בשרת SQL בגרסת WEB:
BACKUP failed to complete the command BACKUP DATABASE DatabaseName. Check the backup application log for detailed messages.
BACKUP DATABASE WITH COMPRESSION is not supported on Web Edition (64-bit).
Database backed up. Database: DatabaseName<c/> creation date(time): 2011/12/21(07:06:41)<c/> pages dumped: 233<c/> first LSN: 44:2367:1<c/> last LSN: 44:2369:1<c/> number of dump devices: 1<c/> device information:..... This is an informational message only. No user action is required.
|
By ronen ariely on
16/02/2012 07:27
מבט כללי על היחסים בין האלמנטים השונים במסד הנתונים:
מסדי הנתונים של SQL כוללים אלמנט בשם Database Diagram המאפשר לנו לבנות דיאגראמות לצפייה ועבודה (עדכון ובנייה) של אלמנטים שונים במסד הנתונים כגון טבלאות והקשרים בין הטבלאות.
נעבור בקצרה בבלוג זה על הדרך בה נוכל להקים דיאגראמות שונות לעזרה בניהול הקשרים של הטבלאות שלנו.
|
By ronen ariely on
14/02/2012 11:16
הודעת שגיאה בקבצי הלוג של שרת ה SQL
בקריאה לפתרון מצב שקובץ הלוג (הכוונה לקובת לוג השגיאות ולא לוג של מסד נתונים) התמלא בקריאות, התברר לי כבר במבט ראשון שכל הודעות האזהרה והשגיאה מוכרות וידועות והפתרון בהתאם. בשבוע הקרוב אכתוב בלוג אחד או יותר לגבי שגיאות נפוצות שנראות בקובץ הלוגים של שרת ה SQL ונתחיל עם ההודעה:
A significant part of sql server process memory has been paged out. This may result in a performance degradation. Duration: 0 seconds. Working set (KB): 58868<c/> committed (KB): 115472<c/> memory utilization: 50%.
|
By ronen ariely on
20/12/2011 08:16
בגרסת 2008 של שרתי SQL נוספה יכולת חזקה מאוד לעבודה עם תפיסת שינויים בנתונים בטבלאות (DML) בשם Change Data Capture או בשם המקוצר CDC. הרעיון הבסיסי הוא שבמקום להוסיף טריגר שתופס אירוע בזמן שהוא קורה, הרי ש CDC מתבסס על קבצי הלוג בהם נרשמת כל פעולת שינוי DML. * אפשרות זו עובדת רק בגרסאות Enterprise, Developer, וגרסאות הערכה! מדריכון קצר זה נועד רק להציג את האפשרות ולא מהווה מדריך מלא לשימוש. בסופו של המדריך כללתי קישורים רלוונטים למדריכים מלאים ולסירטוני הדרכה בסגנון "צעד אחרי צעד"
|
By ronen ariely on
16/11/2011 11:22
בבלוג זה אני מציג פתרון לבעיה שהוצגה באחד הפורומים ברשת. הדגש במדריך יהיה לא רק הצגת הפתרון כי אם הצגת דרך המחשבה ופיתוח הדרך אל הפתרון. בחלק הראשון של המדריך אציג את דרכי המחשבה השונים וכיצד הגענו לפתרונות. בחלק השני נערוך השוואה קצרה בין הפתרונות השונים. ולסייום נציג בחלק השלישי של המדריך נקודות למחשבה שונות ונסביר חלק מהסיבות להבדלים שקיבלנו. כאמור מטרת מדריך זה לא לא רק להצגת פתרון סופי כי אם ההסברים הנלווים לפתרון.
השאלה בה נדון:
השמירה בבניין החברה מתבצעת על ידי שומר העובד במשמרות. בחדר הכניסה לבניין (הלובי) של החברה נרשמים קבצי לוג יומיים של השומרים. בכל כניסה של שומר אל חדר הלובי נרשמת רשומה בקובץ הלוג הכוללת שעת הכניסה ושם המשתמש. עם תחילת כל משמרת מבוצעת למעשה הכניסה הראשונה של השומר אל הבניין ומגדירה את זמן תחילת המשמרת שלו. במשך המשמרת השומר מבצע פטרולים בזמנים לא קבועים ובסופם חוזר אל הלובי. בכל חזרה אל הלובי כאמור נרשמת שוב רשומה בקובץ הלוג המצביעה על כניסת השומר.
* שומר יכול לעבוד יותר ממשמרת. כמו כן אין הגבלה על אורך כל משמרת. ז"א אם שומר A התחיל בבוקר והוחלף על ידי שומר B הרי ששומר A יכול לחזור ולהחליף את השומר הקודם.
המטרה
אנו רוצים למצוא את הכניסה הראשונה של כל משתמש במשמרת מסוימת שלו (על מנת לדעת מתי התחילה המשמרת).
|
By ronen ariely on
11/11/2011 18:34
כיצד נוכל לאפשר דפדוף (חלוקת הרשומות לדפים ומעבר בין הדפים) כאשר אנו רוצים לקבל את הרשומות בסדר אקראי?
המורכבות של השאלה נובעת מכך שמצד אחד אנו רוצים לשלוף את הנתונים (או לסדר את הרשומות אחרי השליפה) בסדר אקראי עבור כל משתמש. כך שכל משתמש יקבל את הרשומות בסדר שונה ולכן גם החלוקה של הרשומות לעמודים תהיה שונה, אבל מצד שני אנו רוצים לאפשר למשתמש לנווט בין העמודים השונים כך שעבור המשתמש המסוים ישמר הסדר וחלוקת הרשומות לעמודים תהיה קבועה.
אחרי הכול לא נרצה שהמשמש יעבור לעמוד 2 ויקבל שוב נתונים מעמוד 1 או שכאשר המשתמש יחזור לעמוד 2 אחרי שביקר בעמוד 3 הוא פתאום יקבל תוצאה שונה של רשומות.
ננסה לתת מענה לאפיון המדובר במדריך הקצר הבא
|
By ronen ariely on
02/11/2011 14:59
לא ניתן למנוע לחלוטין במסד נתונים פעיל וגדול מצב של deadlock אבל בהחלט ניתן להקטין את האפשרות להגיע למצב כזה בצורה דרסטית מאוד ולגבי שאילתה ספציפית ניתן גם למנוע מצב זה לחלוטין. לצערי לא צירפת לנו DDL+DML+שאילתה שאתה מנסה להריץ ולכן אנחנו רק מדברים כרגע על תיאוריה. במדריך קצר זה אציג כמה מהפעולות שיכולות לעזור לכם להיגרר לבעיות הקשורות בנעילות.
|
By ronen ariely on
25/09/2011 19:03
לא תמיד אנחנו יודעים מראש איזה תוצאות יגעו לנו בשאילתה ואנו רוצים לבצע פעולה של PIVOT או פשוט הפיכת שורות ועמודות. בשאילתה הבאה מציגה קוד לבניית שאילתה דינאמית של PIVOT
|
By ronen ariely on
26/08/2011 14:39
קידוד תווים הנו התאמה בין קבוצת תווים לקבוצה אחרת. דוגמה פשוטה ומוכרת לקידוד תווים הוא קוד ASCII, המקודד אותיות, ספרות וסימנים אחרים למספרים בינאריים. קוד ASCII מייצג את האלפבית הלטיני הפשוט, מספרים וסימני פיסוק אבל מביא לנו גם ייצוג להוראות שאינן תווים קריאים.
מדריך זה ידון בתו הראשון שיש לנו בקידוד ASCII, תו אפס או בשמו Null character המוכר גם בשם null terminator.
|
By ronen ariely on
25/08/2011 16:56
הודעת שגיאה: The SQL Server Agent (MSSQLSERVER) service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service נעבור בקצרה על מקור הבעיה והפתרון
|
By ronen ariely on
16/08/2011 20:44
במדריך זה נציג כיצד אפשר לסדר רשומות שנבחרו ממסד הנתונים בסדר אקראי. כפי שנראה אופן העבודה של מסדי הנתונים בשוק שונה ואפילו כאשר קיימת פונקציה משותפת בשם או בפעולה שלה, אז לא תמיד ההתנהגות והתוצאות המתקבלות משימוש בפונקציה זו תחת שאילתה הרצה של טבלה אכן זהות. ההתנהגות השונה של מסדי נתונים שונים מחייבת אותנו עבודה שונה בהתאם.
במשך ההסבר הכללי אציג קוד התואם לשרתי MS-SQL. עם זה מדריך זה מופנה כאמור לכל שרתי ומסדי הנתונים השונים המרכזיים שיש בשוק. אשים דגש על המורכבות בגישה ישירה לבעיה שקיימת בשרתים השונים ובהמשך אציג פתרונות עבור שרתים ומסדי נתונים שונים.
הרעיון המרכזי מאחורי הפתרון המוצג כאן במדריך הוא יצירה של שדה נוסף לאחר בחירת הנתונים, אשר הערכים שלו יקבעו בצורה רנדומאלית בזמן ריצה. לכן נוכל לבצע בסיום סידור של הנתונים לפי שדה זה ולקבל למעשה את שליפת הרשומות בסדר אקראי.
* נדגיש כבר בנקודה זו ששיטה זו אינה יעילה לבחירת מספר רשומות בצורה אקראית ממסד הנתונים אלא נועדה כאמור להראות כיצד לסדר את הרשומות שבוחרים בצורה אקראית. לנושא בחירת רשומות בצורה אקראית כתבתי מדריך אחר.
|
By ronen ariely on
06/08/2011 12:26
העברת כל הקבצים של מסדי הנתונים למיקום חדש
צריכים להעביר את הקבצים של מסדי הנתונים למיקום אחר? הדיסק מלא ורוצים להעביר את הקבצים לדיסק אחר? ננסה להראות כיצד ניתן לבצע זאת באמצעות שמוש בפונקציות המובנות Detach וכן Attach
|
By ronen ariely on
05/08/2011 09:41
בשאילתה פשוטה תוך שימוש בערכים הידועים לנו נראה כיצד נציג את כל ערכי המאפיינים של השרת. * הערה: בעבר פרסמתי בלוג עם המלצה לבנות בשרת תמיד מסד נתונים כללי שישמש אותנו לתחזוקה. במסד זה נוכל לשים פונקציות ופרוצדורות יעילות כמו גם כלים נוספים לשימוש עתידי. את הפעולה הבאה של יצירת הטבלה אני מליץ להכניס למסד הנתונים של התחזוקה אם בחרתם לייצר כזה
|
By ronen ariely on
03/08/2011 19:16
בלוג קצר יהווה הדגמה פשוטה של כיצד ניתן לקרוא קבצים ששמרנו בשדה בינארי ישירות ממסד הנתונים ולשמור את הקבצים לדיסק, והפוך... נראה כיצד להכניס קבצים אל שדה בינארי.
|
By ronen ariely on
23/07/2011 08:26
כל שרתי הנתונים היום מאפשרים ליצור עמודת דירוג (RANK) בצורה קלה ומהירה. השיטה לייצר עמודה כזו שונה משרת אחד לשני. בהמשך אולי תציג דוגמאות כיצד ניתן לבצע זאת בכל אחד מהשרתים הנפוצים. עם זה לא חסר מאמרים כאלה ברשת האינטרנט. מה שנראה כאן היא שאילתה תקנית בסיסית האמורה לעבוד על שרת נתונים וכל בסיס נתונים (בפרט בסיסי נתונים כקובצי טקסט, אקסל וכל שרתי הנתונים בכלל) בצורה פשוטה ויחסית מהירה.
|
By ronen ariely on
13/07/2011 16:37
מושגים כלליים בנושא אינדקסים
|
By ronen ariely on
05/07/2011 07:10
ייבוא מאקסס ל ms SQL
מדריך צעד אחרי צעד בתמונות
מכירים את המשפט תמונה שווה אלף מילים?
|
By ronen ariely on
29/04/2011 16:11
1. כפתור ימני על מסד הנתונים שרוצים לגבות
2. בחר ב Tasks -> Generate Scripts
...
|
By ronen ariely on
13/04/2011 20:02
מייקרוסופט מחזיקה מספר קבוצות משתמשים מקצועיות לתחומים שונים הקשורים לטכנולוגיות של חברת מייקרוסופט.
אחת מקבוצות אלו היא קבוצת המשתמשים של שרתי SQL בה אני לוקח חלק בפגישות (כשאני יכול). לאחרונה הצטרפה הקבוצה כקבוצה הישראלית הרישמית של קבוצת המשתמשים העולמית PASS - Professional Association for SQL Server אתר בית נפתח לקבוצה תחת אתר PASS בכתובת:
http://israel.sqlpass.org
|
By ronen ariely on
31/03/2011 23:12
נציג דוגמה לקו מחשבה להגעה לפתרון פשוט של בעיה עם טבלאות מקושרות. פתרון זה אינו הפתרון המיטבי ומוצג כפתרון לימודי ולשם הצגת קוו מחשבה כאמור לדרך בה ניתן היה להגיע לפתרון על ידי פירוק הבעיה המקורית לגורמים שלה השאלה המקורית: רישמו שאילתה המציגה את החיה שמספר הספקים שמספקים לה מזון הוא הנמוך ביותר, אבל שיש לה לפחות שני ספקים שונים המספקים לה מזון
|
By ronen ariely on
28/02/2011 08:33
המטרה: מציאת נתונים כפולים. בבלוג זה אציג בקצרה שיטות שונות למציאת נתונים כפולים בטבלה. במקרה הפשוט זה יכול להיות מצב של רשומות זהות לחלוטין שיש לנו בטבלה יותר מפעם אחת (כל הטורים של הרשומה זהים לרשומה אחרת)במצב יותר מוכר ומורכב ידובר על רשומות בהן רק חלק מהטורים זהים ועלינו למצוא את הרשומות (למשל במצב בו יש לנו טור IDINTITY שיהיה שונה ברשומות בהם שאר הנתונים זהים).
הדוגמה בה נדון: יש לנו טבלת שמות ואנחנו רוצים למצוא את כל השמות המופיעים בטבלה יותר מפעם אחת. ז"א אנחנו רוצים למצוא רשומות בהם יש לנו כפילות של שמות (שם פרטי וכן שם משפחה).
|
By ronen ariely on
08/02/2011 21:56
כיצד נוכל להריץ שאילתות בתוכנת האקסס?
נתחיל מקובץ חדש ריק...
|
By ronen ariely on
25/01/2011 21:14
מסד נתונים Access בשרת 64 ביט
במדריכון זה נסביר מעט על הרצת אתרים המתבססים על מסד נתונים Access בשרת 64 ביט...
|
By ronen ariely on
28/12/2010 14:26
|
By ronen ariely on
25/12/2010 13:25
במשך ההסבר בכללי אציג קוד התואם לשרתי MS-SQL. עם זה מדריך זה מופנה לכל שרתי ומסדי הנתונים השונים ומציג רעיון מחשבתי יותר מקוד ספציפי. בהמשך אציג פתרונות עבור שרתים ומסדי נתונים שונים.
נדון בשלושה מקרים שונים לשליפת רשומה אקראית מבין כל הרשומות. ננסה לתת פתרון שמצד אחד יהיה פשוט מבחינת הלוגריתמים וההבנה שלו ומצד שני יהיה יעיל. נתחיל את הדיון במקרה הפשוט ביותר בו יש לנו שדה מפתח ייחודי מסוג IDENTITY ללא רווחים. נעבור בהדרגה לדון במצב בו יש לנו שדה ייחודי מספרי כלשהו (מקרה כללי יותר של מצב של שדה ייחודי IDENTITY עם רווחים במספור), נתקדם למקרה השני בו נדון כשיש לנו שדה ייחודי טקסטואלי ומכאן נעבור למקרה האחרון בו נדון במצב כללי בו לא נעזרים בנתונים קיימים בטבלה (יתאים לכל טבלה ולכל סוגי השדות).
|
By ronen ariely on
22/12/2010 11:04
Pass parameter to OleDbCommand
|
By ronen ariely on
22/12/2010 10:12
פונקציות לעבודה עם טקסטים - דוגמאות והסברים.
|
By ronen ariely on
11/12/2010 22:36
AdventureWorks הוא מסד נתונים חינמי שניתן להוריד מחברת מייקרוסופט ונועד לעזור למפתחים. רבים מהדוגמאות נכתבים עבור מסד זה וההנחה היא שכל מפתח מחזיק מסד נתונים זה בשרת הפיתוח שלו.
|
By ronen ariely on
11/12/2010 22:21
איזה שיטה יעילה יותר והאם נעשה בהם שימוש "חכם" זהה, כשהדעת נותנת שלאחר שנמצאה התאמה אחת המערכת תפסיק לחפש ולא תמשיך לבדוק לחינם את כל הטבלה שבצד הרבים. על כך לא היה חילוקי דעות, אך האם הביצוע יהיה זהה בכל שיטה? כדאי לבדוק!
והעיקר המסקנה... האם הדרך הנכונה לעשות זאת היא בעזרת Exists או In ?!?
|
By ronen ariely on
01/12/2010 08:33
השימוש ב OPENROWSET הוכנס מגרסה MS-SQL 2005. OPENROWSET מאפשר לנו לעבוד עם נתונים חיצוניים. לגשת לקבצים, לגשת למסדי נתונים חיצוניים ולמעשה לבצע כמעט כל פעולה שרוצים על אובייקט חיצוני.
נדגים את השימוש ב OPENROWSET בצורה מעשית
|
By ronen ariely on
09/11/2010 01:16
SQL diagnosing links and help guid. שימוש בפרוצדורות לא רשמיות
|
By ronen ariely on
04/11/2010 04:12
דירוג רשומות לפי עמודה מסוימת
רוצים למשל לדרג את כל הסטודנטים באותו קורס עבור כל קורס בנפרד
|