1、外文原文 Introduction to SQL Server By Samuel Relational databases have been around for 30 years, but they were not the original kind ofdatabase, nor are they the newest kind of database. XML and object-oriented data structures haveevolved in recent years. But relational databases are still by far the m
2、ost popular kind of database available and will be for some time to come. SQL is the abbreviation of Structured Query Language and it is for relational databases, as the title indicates this is only for fresher who has just started the carrier or who is waiting to open up the carrier in the applicat
3、ion programming side. But that does not mean this article is a tutorial for a fresher who does not know anything about SQL.This article is meant for who already have a little knowledge in SQL and want toimprove it. What Does SQL Do? First, SQL is the premier tool for viewing information from a relat
4、ional database. It doesnt just give you a data dump. SQL gives you sophisticated tools to summarize, consolidate, and calculate from the data. Using table relationships, data can be combined from multiple tables in a number of ways. With a properly designed database, SQL can answer practically any q
5、uestion about the data. Second, SQL provides commands to manipulate the data in a relational database. Records can be updated and added to or deleted from a table. Here is SQL as a database language really shines. Procedural programming languages, such as BASIC, might require several lines of code t
6、o update a record in a database table. In addition, procedural programming languages would have to use some sort of looping structure to repeat this process on every record. SQL operates on an entire set of records all at the same time. SQL is like haiku for programmers; often a dozen words or fewer
7、 can delete or change thousands of records. Finally, SQL is a complete data definition language (DDL). The database itself can be created along with all tables, fields, primary keys, and relationships. Add to that the record insert commands, and you can have a complete database and all its data expr
8、essed in programming code. This greatly enhances a database programmers ability to work remotely or to port data enhancements among various installations. The prerequisite for learning SQL is knowledge in Discrete Mathematics (Set Theory,Relations and Functions). Although it is not necessary to lear
9、n all the theorems and proof for the theorems in the Discrete Mathematics, you should have learned the basic concepts of the Sets, Relations and Functions. This will help you to learn SQL queries and fundamentals easily. If you want to explore a RDBMS more deeply you should learn Graph Theory too. A
10、lthough I tried to avoid SQL Server specific topics in this article, I am sure that some topics are pure to SQL server such as SQL Enterprise manager. Data to DBMS Data is something that should be stored for future manipulations (In terms of Database). The system which provides such a facility is ca
11、lled Database Management System or DBMS. The simplest form to store a data for latter retrieval is using a text file. For example you may want to store your friends name and phone numbers to use it latter. (In this case you may use notepad or word to do so.) This kind of storage is called flat file
12、storage or unstructured storage. In this case the text editor uses the File and Directory services provided by the Operating System to accomplish the task of storing and retrieving data. But these unstructured flat files are not suitable to large data such as storing stock details. Since the stock d
13、ata is large in volume and added and updated frequently it is not scale up well if we use a simple flat file. To overcome this we need some system which should perform the storing, retrieving, manipulating and querying operations on the data and give output to us. This kind of system is called Datab
14、ase Management System. So a DBMS is a system which organizes and stores data in a structural way for fast retrieval. A DBMS uses one or more files to store the given data. Since the DBMS is meant mainly for developers every DBMS has it is own language to write the commands. The languages are standar
15、dized under the name SQL(Structured Query Language). The following definition for SQL is from Books Online“A language used to insert, retrieve, modify, and delete data in a relational database.SQL also contains statements for defining and administering the objects in a database. SQL is the language
16、supported by most relational databases, and is the subject of standards published by the International Standards Organization (ISO)and the American National Standards Institute (ANSI). SQL Server 2000 uses a version of the SQL language called Transact-SQL.” Representation of Data by DBMS DBMS should
17、 represent the data stored by them in some form and it is most common to represent them as Column, Row, Tables and Databases. As you know SQL you know what are columns, rows, tables and database. Primary Key A column or set of columns used to uniquely identify the records in a table. Primary Keys do
18、nt allow NULL values. You can relate a table with other table if you have defined primary on it. (So defining UNIQUE and NOT NULL constraint is not equivalent to primary key). SQL server will create a Clustered index while you create a primary key. Primary keys should be carefully defined since base
19、d on it other relations are defined. Poorly designed primary keys will affect insert, update and delete operations. Primary keys are different from which are used for paperwork. Foreign Key The primary key of one of the tables is almost always involved in the relationship. The field in the other tab
20、le on the other end of that relationship is called the foreign key. The term simply refers to the fact that this field is key to relating to a foreign (or other) table. In the Lyric Music database there is a relationship between artists and titles. The ArtistID field is the primary key in the Artist
21、s table. Therefore, the ArtistID field in the Titles table is a foreign key. It relates the Titles table to the primary key in the Artists table. Most table relationships can be described as one-to-many. In a one-to-many relationship, a single record in the first table can be related to many records
22、 in the second table. However, each record in the second table relates to only one record in the first table. In addition to one-to-many relationship, tables can have one-to-one relationships. But these are much less common. Server Client In Client Server technology, a server is a program which does
23、 all the jobs that is requested by the client and Client is a program which depends on the Server to accomplish its task. Client is mainly used to interact with Users and most Server software doesnt have direct interaction with Users. A DBMS should have the following functionality Interaction with u
24、sers (developers),Managing Data. Since these two functionalities are entirely different modern DBMS is divided into two or more parts. Almost all current DBMS has the following module Server and one or more clients. A server module is program which manages the data and handles requests from the clie
25、nt applications. It interprets the SQL queries and returns results back to the clients. A client program is a program which sends SQL commands to server and gets the result. Client program does not know the detailed underground structure of the server. SQL Server 2000 runs as a service in NT based m
26、achines. You have to establish a connection to the server first if you want to do some SQL operation. SQL Server uses Local or Network IPC (Inter process communication) to communicate with the clients. See Books Online for more details. The most basic misunderstanding of many junior developers is considering SQL