|
In our introduction, we saw that an index can make it
possible to take some action during data entry, such as making sure that a
column has unique values for each record or making sure that the combination
of values of a group of columns on the same record produces a unique value.
Besides this characteristic, indexes are actually very valuable when it
comes to data analysis.
|
Practical
Learning: Entering Data
|
|
- Click inside the Query Editor and press Ctrl + A
- To create records, type the following:
USE InformationTechnologyJournal1;
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, MiddleName, LastName, Citizenship)
VALUES(N'297948', N'Eddy', N'Donald', N'Vasquez', N'USA');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, LastName, Citizenship)
VALUES(N'282947', N'Edmond', N'Plane', N'USA'),
(N'294859', N'David', N'Kearney', N'Australia');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, MiddleName, LastName, Citizenship)
VALUES(N'284058', N'Robert', N'Peter', N'Shear', N'UK');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, LastName, Citizenship)
VALUES(N'206486', N'Anthony', N'Goodie', N'South Africa');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, MiddleName, LastName, Citizenship)
VALUES(N'280485', N'Elisabeth', N'Laureen', N'Kirchner', N'USA'),
(N'248374', N'Gérard', N'Laurent', N'Benardin', N'France'),
(N'282504', N'Joseph', N'Emmett', N'Buyck', N'Holland');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, LastName, Citizenship)
VALUES(N'280486', N'Lucie', N'Kearns', N'USA');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, MiddleName, LastName, Citizenship)
VALUES(N'284905', N'Evelyne', N'Laurie', N'Lawson', N'USA'),
(N'240486', N'Frank', N'Jeffrey', N'Avery', N'Canada'),
(N'200468', N'Pamela', N'Amelia', N'Lotts', N'UK');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, MiddleName, LastName, Citizenship)
VALUES(N'240858', N'Cindy', N'Anne', N'Angel', N'Mexico'),
(N'260850', N'Joan', N'Daniela', N'Kean', N'USA');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, LastName, Citizenship)
VALUES(N'204068', N'Andrew', N'Post', N'New Zealand');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, MiddleName, LastName, Citizenship)
VALUES(N'280680', N'Deborah', N'Christine', N'Chisohlm', N'Brasil'),
(N'280684', N'Kyle', N'Robert', N'Greenwood', N'USA');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, LastName, Citizenship)
VALUES(N'249595', N'Larry', N'Metzer', N'Canada');
GO
INSERT INTO Authorship.Reviewers(ReviewerNumber, FirstName, MiddleName, LastName, Citizenship)
VALUES(N'249696', N'Maureen', N'Holly', N'Dorryan', N'USA');
GO
INSERT INTO Publishing.Affiliations(AffiliationCode, AffiliationName)
VALUES(N'MDUNV', N'Maryland University'),
(N'MSCOL', N'Maryland State College'),
(N'AIRAT', N'Australia Institute of Research and Technologies'),
(N'INPNT', N'Institute or Paranormal Technologies'),
(N'VASTU', N'Virginia State University'),
(N'IFTEM', N'Institut Français des Technologies Modernes'),
(N'ASSIS', N'Association of Information Systems'),
(N'ITNFD', N'International Technocrate Foundation');
GO
INSERT INTO Authorship.ReviewersAffiliations(ReviewerNumber, AffiliationCode)
VALUES(N'297948', N'INPNT'), (N'282947', N'AIRAT'), (N'294859', N'ASSIS'),
(N'284058', N'MDUNV'), (N'206486', N'ITNFD'), (N'280485', N'VASTU'),
(N'248374', N'IFTEM'), (N'282504', N'MSCOL'), (N'280486', N'INPNT'),
(N'240858', N'VASTU'), (N'260850', N'ITNFD'), (N'204068', N'MDUNV'),
(N'280680', N'ITNFD'), (N'280684', N'ASSIS'), (N'249595', N'MSCOL'),
(N'249696', N'AIRAT');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, MiddleName, LastName, Citizenship, DateOfBirth)
VALUES(N'924935', N'Margareth', N'Anne', N'Gundlehach', N'USA', N'19520612');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, LastName, Citizenship)
VALUES(N'180047', N'Edward', N'Pomerantz', N'Canada');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, MiddleName, LastName, Citizenship, DateOfBirth, DateOfDeath)
VALUES(N'637444', N'Laura', N'Jeannine', N'Wayne', N'USA', N'19180805', N'19861230');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, LastName, Citizenship, DateOfBirth)
VALUES(N'386079', N'Jonas', N'Mensah', N'Ghana', N'19751004');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, MiddleName, LastName, Citizenship)
VALUES(N'862947', N'Danielle', N'Justine', N'Wilder', N'Australia');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, MiddleName, LastName, Citizenship, DateOfBirth)
VALUES(N'685948', N'Christopher', N'James', N'Dowdy', N'USA', N'19600510'),
(N'629479', N'Françoise', N'Hélène', N'Guignon', N'France', N'19700618');
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, LastName, Citizenship, DateOfBirth)
VALUES(N'374704', N'Maheen', N'Haana', N'Brunei', N'19850904');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, LastName, Citizenship, DateOfBirth, DateOfDeath)
VALUES(N'462804', N'Erin', N'Spears', N'UK', N'19221114', N'20000502');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, LastName, Citizenship)
VALUES(N'830418', N'Johann', N'York', N'USA');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, LastName, Citizenship, DateOfBirth)
VALUES(N'480507', N'Daniela', N'Palau', N'Mexico', N'19780415');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, MiddleName, LastName, Citizenship, DateOfBirth)
VALUES(N'183958', N'Bertrand', N'Alain', N'Prison', N'Canada', N'19821008');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, LastName, Citizenship, DateOfBirth)
VALUES(N'528484', N'Peter', N'Walden', N'New Zealand', N'19560622');
GO
INSERT INTO Authorship.Authors(AuthorNumber, FirstName, MiddleName, LastName, Citizenship, DateOfBirth)
VALUES(N'940759', N'Meghan', N'Danielle', N'Brawer', N'USA', N'19810422');
GO
INSERT INTO Publishing.AreasOfInsterest(AreaOfInterest, [Description])
VALUES(N'Operating Systems', N'This includes all types of operating systems, whether on desktops or servers. This also covers Oss in cell phones and other portable devices. This also includes operating systems in industrial devices used in health care, cars, or robotics, etc.'),
(N'Application Programming', N'This includes all computer languages such as C-based (C, C++, Java, and C#), web-based languages (JavaScript, VBScript, PHP, etc), and others.'),
(N'Network Design, Setup, and Administration', N'This area deals with techniques to design, create, and manage a computer network'),
(N'Network/Information Security', N'All types of computer security issues are dealt with, including availability or lack of, accessibility or lack of, etc.'),
(N'Database Administration', N'Database administration deals with both desktop and enterprise ways to create and manage databases, regardless of their sizes.'),
(N'Database Developement', N'Database development includes desktop and enterprise database developement as well as means to provide access to all types of devices, including tablet PCs (portable computers) and others.'),
(N'Web Design and Development', N'This includes different topics on the arts of web design as well as general views of web development, mainly the programmatic functionalities or dynamic web sites or web services. This area (or the articles) may or may not include actual programming).'),
(N'Robotics', N'Robotics include industrial machines as well as small devices such as printers.');
GO
INSERT INTO Authorship.ReviewersAreasOfInsterest(ReviewerNumber, AreaOfInsterestID)
VALUES(N'297948', 1001), (N'297948', 1008), (N'297948', 1003), (N'282947', 1002),
(N'294859', 1005), (N'248374', 1001), (N'248374', 1008), (N'284058', 1006),
(N'284058', 1007), (N'206486', 1001), (N'280485', 1003), (N'280485', 1008),
(N'280485', 1004), (N'282504', 1008), (N'280486', 1007), (N'280486', 1006),
(N'240858', 1007), (N'260850', 1008), (N'260850', 1002), (N'260850', 1007),
(N'260850', 1006), (N'204068', 1003), (N'204068', 1006), (N'280680', 1004),
(N'280684', 1001), (N'280684', 1006), (N'249595', 1005), (N'249696', 1004);
GO
INSERT INTO Authorship.Manuscripts(ManuscriptCode, Title)
VALUES(N'2683-0475', N'Transitioning From Desktop to Enterprise Database'),
(N'4005-0618', N'Information Transmission in Health Care Management'),
(N'6028-3058', N'General Data Analysis on Electronic Spreadsheets'),
(N'4293-7405', N'Etude Méthodique des Sites Web Intéractifs'),
(N'8060-0568', N'Comparative Study of Microsoft Windows and Linux'),
(N'2947-5085', N'Approaches to Exception Handling in Microsoft SQL Server'),
(N'9270-4957', N'Overview of Printing Functionality'),
(N'2848-6158', N'Introduction of Biometric Authentication');
GO
INSERT INTO Authorship.Manuscripts(ManuscriptCode, Title, Notes)
VALUES(N'5020-4860', N'Quelle Language Informatique Est Approprié Pour Votre Site Web? ', N'Choosing the Appropriate Computer Language for Your Website'),
(N'6040-5968', N'Fundamentos de Certificados de Aplicaciones para la Web', N'Foundations of Application Certificates for the Web');
GO
INSERT INTO Authorship.Manuscripts(ManuscriptCode, Title)
VALUES(N'9285-4068', N'The Evolution of C-Based Languages'),
(N'9713-0475', N'Information Assurance and the Current Cultural Environment'),
(N'2845-0684', N'Error and Exception Handling: Is There a Difference?'),
(N'9203-9472', N'What Happened to OS/2?'),
(N'7024-7058', N'Context-Based Security in Oracle Databases');
GO
INSERT INTO Authorship.ManuscriptsStatus(ManuscriptStatus, [Description])
VALUES(N'Approved', N'This implies that the manuscript has been approved and is ready for publication or it has been published.'),
(N'Assigned', N'This means that the manuscript has been assigned to a reviewer'),
(N'In Transition', N'The manuscript has been received but it is "traveling" somehow. This means that the manuscript is not currently under one particular person or institution care. This status should be as temporary and short as possible.'),
(N'Received', N'This indicates that a manuscript has been received but no other action has been taken towards it'),
(N'Rejected', N'The manuscript has been checked and reviewed but was deemed unworthy of publication'),
(N'Under Review', N'This option is for a manuscript that has been received, assigned to a reviewer, and the reviewer wants to indicate that he/she is still working on it. In other cases, a reviewer has received the script a second time and reviewing it once more.');
GO
INSERT INTO Authorship.ManuscriptsAuthors(AuthorNumber, ManuscriptCode)
VALUES(N'685948', N'4005-0618'), (N'940759', N'2848-6158'), (N'637444', N'2845-0684'),
(N'180047', N'8060-0568'), (N'386079', N'2683-0475'), (N'685948', N'7024-7058'),
(N'462804', N'9203-9472'), (N'940759', N'6028-3058'), (N'629479', N'5020-4860'),
(N'374704', N'2947-5085'), (N'629479', N'4293-7405'), (N'830418', N'7024-7058'),
(N'924935', N'9285-4068'), (N'862947', N'2848-6158'), (N'830418', N'2848-6158'),
(N'180047', N'9713-0475'), (N'183958', N'4293-7405'), (N'480507', N'6040-5968'),
(N'528484', N'9270-4957');
GO
INSERT INTO Authorship.ManuscriptsRatings(ManuscriptRating, Explanation)
VALUES(N'1 - Poor', N'The work was poorly done and the manuscript should not be further considered. The manuscript should be wholly rejected.'),
(N'2 - Insufficient', N'The manuscript lacks work. It may not be rejected if more work is done on it.'),
(N'3 - Acceptable', N'If no rigorous work is required, the manuscript can be published (acceptable) but could also be improved.'),
(N'4 - Good', N'The manuscript is well written and can seriously be considered for publication.'),
(N'5 - Excellent', N'The work done is without flaws and meets the highest standards in litterature and field.');
GO
INSERT INTO Authorship.ManuscriptsReviewUpdates(DateUpdated, ReviewerNumber, ManuscriptCode, ManuscriptRating)
VALUES(N'20121122', N'280485', N'4005-0618', N'4 - Good'),
(N'20121127', N'297948', N'4293-7405', N'5 - Excellent'),
(N'20121127', N'280680', N'4005-0618', N'4 - Good'),
(N'20121128', N'280485', N'2848-6158', N'2 - Insufficient'),
(N'20121130', N'280485', N'2683-0475', N'1 - Poor'),
(N'20121203', N'280680', N'2848-6158', N'1 - Poor'),
(N'20121206', N'284058', N'4293-7405', N'4 - Good'),
(N'20121212', N'280680', N'9713-0475', N'3 - Acceptable'),
(N'20121212', N'297948', N'6040-5968', N'5 - Excellent'),
(N'20121212', N'248374', N'9203-9472', N'5 - Excellent'),
(N'20121212', N'282947', N'9285-4068', N'5 - Excellent'),
(N'20121213', N'248374', N'9270-4957', N'1 - Poor'),
(N'20121214', N'248374', N'6028-3058', N'4 - Good'),
(N'20121214', N'284058', N'6028-3058', N'3 - Acceptable'),
(N'20121215', N'280485', N'7024-7058', N'4 - Good'),
(N'20121215', N'248374', N'2683-0475', N'2 - Insufficient'),
(N'20121215', N'260850', N'9285-4068', N'5 - Excellent'),
(N'20121216', N'280485', N'2848-6158', N'3 - Acceptable'),
(N'20121220', N'280680', N'6028-3058', N'4 - Good'),
(N'20121220', N'284058', N'5020-4860', N'4 - Good'),
(N'20121222', N'249696', N'6028-3058', N'4 - Good'),
(N'20121228', N'248374', N'8060-0568', N'5 - Excellent'),
(N'20121230', N'206486', N'9285-4068', N'3 - Acceptable'),
(N'20130103', N'282947', N'2845-0684', N'4 - Good'),
(N'20130105', N'280680', N'7024-7058', N'5 - Excellent'),
(N'20130108', N'204068', N'9713-0475', N'4 - Good'),
(N'20130110', N'280684', N'9285-4068', N'4 - Good'),
(N'20130111', N'260850', N'5020-4860', N'5 - Excellent'),
(N'20130115', N'280680', N'2947-5085', N'4 - Good');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121116', N'2683-0475', N'Received'), (N'20121116', N'4005-0618', N'Received'),
(N'20121116', N'6040-5968', N'Received'), (N'20121120', N'6028-3058', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121120', N'6040-5968', N'Assigned', N'297948'),
(N'20121121', N'4005-0618', N'Assigned', N'280485'),
(N'20121122', N'6040-5968', N'Under Review', N'297948');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121124', N'4293-7405', N'Received'), (N'20121124', N'7024-7058', N'Received'),
(N'20121126', N'2848-6158', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121126', N'4005-0618', N'Assigned', N'280680'), (N'20121126', N'4293-7405', N'Assigned', N'297948'),
(N'20121127', N'2683-0475', N'Assigned', N'280485'), (N'20121128', N'2848-6158', N'Assigned', N'280485');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121128', N'4005-0618', N'Approved'), (N'20121128', N'9203-9472', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121130', N'6040-5968', N'Under Review', N'297948'), (N'20121130', N'7024-7058', N'Assigned', N'280680');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121201', N'8060-0568', N'Received'), (N'20121201', N'9270-4957', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121201', N'2848-6158', N'Assigned', N'280680');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121201', N'9285-4068', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121202', N'7024-7058', N'Under Review', N'280680'), (N'20121202', N'4293-7405', N'Assigned', N'284058');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121204', N'5020-4860', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121205', N'4293-7405', N'Under Review', N'284058'), (N'20121206', N'6040-5968', N'Under Review', N'297948');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121208', N'9713-0475', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121210', N'8060-0568', N'Assigned', N'248374'), (N'20121210', N'7024-7058', N'Under Review', N'280680'),
(N'20121210', N'9285-4068', N'Assigned', N'282947');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121212', N'9270-4957', N'Assigned', N'248374'), (N'20121214', N'2683-0475', N'Assigned', N'248374'),
(N'20121215', N'6028-3058', N'Assigned', N'248374'), (N'20121215', N'6028-3058', N'Assigned', N'284058'),
(N'20121215', N'9713-0475', N'Assigned', N'204068');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121215', N'2683-0475', N'Rejected');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121215', N'9285-4068', N'Assigned', N'260850'),
(N'20121215', N'7024-7058', N'Under Review', N'280680'),
(N'20121216', N'2848-6158', N'Under Review', N'280485'),
(N'20121216', N'9713-0475', N'Assigned', N'280680'),
(N'20121218', N'5020-4860', N'Assigned', N'284058'),
(N'20121218', N'6028-3058', N'Assigned', N'280680'),
(N'20121220', N'9713-0475', N'Under Review', N'204068');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121220', N'2845-0684', N'Received'),
(N'20121220', N'2845-0684', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121220', N'6028-3058', N'Assigned', N'249696'),
(N'20121220', N'5020-4860', N'Assigned', N'260850'),
(N'20121222', N'2845-0684', N'Assigned', N'282947');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121226', N'2947-5085', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121226', N'2947-5085', N'Received');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo, Notes)
VALUES(N'20121228', N'7024-7058', N'Under Review', N'280680', N'Translated from French to English by Walter Englund.');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121228', N'5020-4860', N'Approved'), (N'20121228', N'5020-4860', N'Approved');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20121228', N'9713-0475', N'Under Review', N'204068'),
(N'20121229', N'2947-5085', N'Under Review', N'280680');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121230', N'2947-5085', N'Approved'), (N'20121230', N'9270-4957', N'Rejected');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, Notes)
VALUES(N'20121230', N'8060-0568', N'Approved', N'Translated from French to English by Walter Englund.');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20121230', N'4293-7405', N'Approved'), (N'20121230', N'6028-3058', N'Approved'),
(N'20121230', N'2848-6158', N'Approved'), (N'20121230', N'2848-6158', N'Approved');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20130102', N'7024-7058', N'Assigned', N'280485');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20130110', N'2845-0684', N'Approved');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus, AssignedTo)
VALUES(N'20130103', N'9713-0475', N'Under Review', N'204068');
GO
INSERT INTO Authorship.ManuscriptsStatusChanges(DateChanged, ManuscriptCode, ManuscriptStatus)
VALUES(N'20130115', N'7024-7058', N'Approved'), (N'20130115', N'9203-9472', N'Approved'),
(N'20130115', N'9285-4068', N'Approved'), (N'20130115', N'9713-0475', N'Approved');
GO
- Press F5 to execute
|
Introduction to Index Uniqueness
|
|
An index is made valuable in two ways. On one hand, the
records should be sorted. A clustered index itself takes care of this aspect
because it automatically and internally sorts its records. What if the
records are not unique? For example, in a bad data entry on a list of
employees, you may have two or more employees with the same employee's
records. If you create an index for such a table, the database engine would
create duplicate records on the index. This is usually not good because when
it comes time to select records, you may have too many records and take a
wrong action.
When creating a table, you can create an index for it
and let the index apply a rule that states that each record would be unique.
To take care of this, you can apply a uniqueness rule on the index. If you
are visually creating an index:
- If you are using the New Index dialog box, under Index Type, click
the Unique check box

- If you are using the Indexes/Keys dialog box, select the index on
the left side. On the right list, set the Is Unique field to Yes
To create a uniqueness index in SQL, apply the UNIQUE
keyword in the formula:
CREATE [UNIQUE] [CLUSTERED | NONCLUSTERED]
INDEX index_name ON Table/View(Column(s))
Start with the CREATE UNIQUE expression,
then specify whether it would be clustered or not. The rest follows the
descriptions we saw previously. Here is an example:
CREATE TABLE Employees
(
EmployeeNumber int NOT NULL,
LastName nvarchar(20) NOT NULL,
FirstName nvarchar(20),
Username nchar(8) NOT NULL,
DateHired date NULL,
HourlySalary money
);
GO
CREATE UNIQUE CLUSTERED INDEX IX_Employees
ON Employees(EmployeeNumber);
GO
If an index is unique but you want to reverse this
characteristic:
- If you are using the New Index dialog box, under Index Type, remove
the check mark on the Unique check box
- If you are using the Indexes/Keys dialog box, select the index on
the left side. On the right list, set the Is Unique field to No
|
Unique Indexes and Data Entry
|
|
Once you have specified the uniqueness of an index on a
table, during data entry, if the user enters a value that exists in the
table already, an error would be produced. Here is an example:
INSERT INTO Employees(EmployeeNumber, FirstName,
LastName, HourlySalary)
VALUES(92935, N'Joan', N'Hamilton', 22.50)
GO
INSERT INTO Employees(EmployeeNumber, FirstName,
LastName, HourlySalary)
VALUES(22940, N'Peter', N'Malley', 14.25)
GO
INSERT INTO Employees(EmployeeNumber, FirstName,
LastName, HourlySalary)
VALUES(27495, N'Christine', N'Fink', 32.05)
GO
INSERT INTO Employees(EmployeeNumber, FirstName,
LastName, HourlySalary)
VALUES(22940, N'Gertrude', N'Monay', 15.55)
GO
INSERT INTO Employees(EmployeeNumber, FirstName,
LastName, HourlySalary)
VALUES(20285, N'Helene', N'Mukoko', 26.65)
GO
This would produce:
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
Msg 2601, Level 14, State 1, Line 1
Cannot insert duplicate key row in
object 'dbo.Employees' with unique index 'IX_Employees'.
The statement has been terminated.
(1 row(s) affected)
You have the option of using an index when you want or
asking the database engine to ignore it for some operations. This is done by
disabling the index. Of course, you do this after creating the index, that
is, by modifying an existing index.
To disable an index, create an ALTER INDEX
statement and add the DISABLE flag before the end statement.
|
Practical
Learning: Disabling an Index
|
|
- Click inside the Query Editor and press Ctrl + A
- To create records, type the following:
USE InformationTechnologyJournal1;
GO
ALTER INDEX IX_ReviewersCitizenships ON Authorship.Reviewers
DISABLE;
GO
- To execute, on the SQL Editor toolbar, click the Execute button

By default, an index includes all records that involve
the columns specified in the parentheses of the table. Instead of
considering all records when looking for values, you can set a condition
that asks the database engine to check only specific records and/or to
ignore some other records. To set the condition, after the name of the table
and its parentheses, create a WHERE condition.
|
Practical
Learning: Setting a Condition on an Index
|
|
- Click inside the Query Editor and press Ctrl + A
- To create records, type the following:
USE InformationTechnologyJournal1;
GO
CREATE NONCLUSTERED INDEX IX_AuthorsCitizenships
ON Authorship.Authors(FirstName, LastName)
WHERE Citizenship = N'USA';
GO
- To execute, on the SQL Editor toolbar, click the Execute button

|
Including Additional Columns
|
|
We have already seen how to specify the columns that
would compose the index. Besides those columns, you can add some others that
can make it fast to find records.
To add columns to an index, when creating it, after the
name of the table and its parentheses, add the INCLUDE keyword and
one or a list of fields.
|
Practical
Learning: Including Additional Columns to an Index
|
|
- Click inside the Query Editor and press Ctrl + A
- To create records, type the following:
USE InformationTechnologyJournal1;
GO
CREATE NONCLUSTERED INDEX IX_AuthorsNames
ON Authorship.Authors(LastName, Citizenship)
INCLUDE (FirstName);
GO
- To execute, on the SQL Editor toolbar, click the Execute button

- Close Microsoft SQL Server
- When asked whether you want to save, click No
|
|