210 likes | 223 Views
Learn about SQL programming language, database management, and SQL Server features. Understand data types, DBMS services, backup and recovery. Get hands-on experience with SQL Query Analyzer.
E N D
Enterprise Database SystemsIntroduction to SQL Server Technological Educational Institution of Larissa in collaboration with Staffordshire University Larissa 2007 Dr. Georgia Garani garani@teilar.gr Dr. Theodoros Mitakosteo_ms@yahoo.com
SQL • SQL, pronounced ‘Sequel’ or simply S-Q-L, is a computer programming language that was developed especially for querying relational databases using a nonprocedural approach. • The term nonprocedural means that you can extract information by simply telling the system what information is needed without telling it how to perform the data retrieval. • Transact-SQL or T-SQL is Microsoft's implementation of the SQL language.
DATA • Two types of data are stored within a database. • User data: Data that must be stored by an organization. • System data: Data the database needs to manage user data to manage itself. This is also termed metadata, or the data about data.
DBMS Services • Data definition for defining and storing all of the objects that comprise a database such as tables and indexes • Data maintenance • Data manipulation • Data display • Data integrity • Data security Database backup and recovery
SQL Query Analyzer GUI can be used to: • Create databases. • Develop, test, and debug stored procedures. • Run SQL scripts – these are miniature programs that contain either DDL or DML commands or a combination of these commands. An example would be a script to create a database, and then populate the tables in the database with data. • Optimize system performance. • Analyze query plans – these are the plans that the DBMS generates for processing a query. • Maintain and manage statistics concerning database performance. • Generate tune table indexes – the indexes are supposed to improve system performance for data retrieval.
Creating a Database • When SQL Server is initially installed, five system databases are generated. These are named: (1) master, (2) model, (3) msdb, (4) distribution, and (5) tempdb. • When you create a new database in SQL Server, the DBMS uses the model database as a template to create a new database. • The command to create a user database is : CREATE DATABASE <database_name> Note: You must have prior authorization from your system administrator to execute this command.
Using a Database • After you have CREATED your database(s) you must use the USE command to select a database for future processing. • You can type the USE command into the Editor pane and execute it also. USE Company; The command(s) completed successfully.
Executing Scripts • Sometimes you need to execute a script that contains a series of SQL statements. The Editor pane can be used to create and save a script • Simply select the Editor pane to make it the active window, then use the toolbar Save option and specify the location, file name, and file format when the Save Query dialog box displays. • You should use the default filename extension of .sql when naming a script file.
Executing Scripts • You can also open scripts and execute them, even if they were created with another text editor, such as Microsoft Notepad or Word. • Select the Load SQL Script toolbar button and when the Open Query File dialog box displays, locate and select the name of the file to be opened.
T-SQL Naming Rules There are several rules for naming database objects that must be followed: • Identifiers can consist of letters, digits, or the symbols #, @, $, and _ (underscore). • Identifiers must be no more than 128 characters • The first character of an identifier must be either a letter (a-z, A-Z) or the #, @ or _ (underscore) symbol. After the first character, you may use digits, letters, or the symbols $, #, or _ (underscore). • Temporary objects are named by using the # symbol as the first character of the identifier. Avoid using this symbol as the leading character when naming permanent database objects. • The @ symbol as the first character of an identifier denotes a variable name. Avoid using this symbol as the leading character when naming other database objects. • SQL keywords such as SELECT and WHERE cannot be used as an identifier.