




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
T-SQL & SQL Server DBPractices Part 1SQL Server Management StudioExercise 1 Exploring the Environment2Exercise 2 Creating a New Database4Exercise 3 Attaching a Database5Exercise 4 Exploring Database7Exercise 5 Create Database ObjectsTables, Views8Exercise 1Exploring the EnvironmentScenarioIn this exercise, you will become familiar with the new SQL Server Management Studio Tool.SQL Server Management Studio is a new tool built for SQL Server 2005. It combines the functionality of the Enterprise Manager snap-in and the Query Analyzer. Although this is the main tool for administering one or more SQL Servers, you can also use the SQL Server Management Studio for executing queries and scripts, and for managing SQL Server projects. The SQL Server Management Studio tool is based on the Microsoft Development Environment used in Visual Studio 2005 to create applications. If you are not already familiar with Visual Studio 2005, using the SQL Server Management Studio tool will help you learn to use the new Microsoft Development Environment for Visual Studio 2005.TasksDetailed Steps1. Open SQL Server Management Studio and connect to your server.1. From the Windows task bar, select Start | All Programs | Microsoft SQL Server 2005 | SQL Server Management Studio.2. When the Connect to Server dialog box appears, verify that Server type is set to Database Engine, Server name is set to localhost, and that Windows Authentication is selected as the authentication method.3. Click the Options button to display additional connection options.4. Click the Connection Properties tab. Note that the following options are available: You can configure the network protocol to use for this connection, which might be different than the protocol you use for other connections. You can configure a connection timeout, which controls how long to wait for the connection to be made. You can configure an execution timeout to specify how long to wait for response from a query.Note that you can export your server registration information, or import registration information from another server. This facility can be valuable for large organizations with many SQL Server administrators who all want to have the same servers registered.5. Click Options again to hide the additional options tabs.6. Click Connect.Note the various areas of the SQL Server Management Studio:The lower left pane is the Object Explorer, which appears as a tree view on the left side of SQL Server Management Studio. Above that is the Registered Servers pane, containing a list of servers to which Management Studio can connect. If the Registered Servers pane is not visible, click the View | Registered Servers menu.The right side of the SQL Server Management Studio contains the tools for managing projects. On the top right is the Solution Explorer. Below that is the Properties Window. If the Solution Explorer is not visible, you can choose to display it by selecting View | Solution Explorer. If the Properties window is not visible, you can also enable that window from the View menu, or by right-clicking on any object in the Solution Explorer window and choosing Properties Window. At the moment, the Solution Explorer is blank because no solution is currently loaded.If you close any of the windows, you can restore them from the View menu. 2. Open new Query to execute a simple SQL clause.1. Open a new query window with File | New | Database Engine Query. When prompted, click Connect in the Connect to Database Engine dialog box. 2. The query window appears in the center portion of the SQL Server Management Studio, and is tabbed with the Summary Page. All additional query windows will be tabbed as well.3. In the query window, enter the following code:EXEC sp_who4. Press F5 or click the Execute button on the toolbar to execute the query.You will see the current active current users and processes in your SQL Server Database Engine.3. Create a Management Studio Project and use a script file from a project.1. Click File | New | Project, and choose SQL Server Scripts in the New Project dialog, type the project name “mySSMSProject”, and then click OK button, then a new Management Studio project is created.2. You should see the mySSMSProject solution in the Solution Explorer window on the right side of the Management Studio. There is no files or connection now, it only has three folders, on the Queries folder, right click and select New Query, the Connect to Database Engine dialog will prompt, confirm your server name and authentication mode and then click Connect button to connect server.3. Type the following SQL clauses:USE masterSELECT SERVERPROPERTY(ServerName)SELECT SERVERPROPERTY(Edition)SELECT SERVERPROPERTY(ProductVersion)SELECT SERVERPROPERTY(ProductLevel)4. To execute the batch, press F5 or click the Execute button on the toolbar. It will show the edition and version number of the SQL Server you are connected to.5. Click File | Save All to Save your first SQL Server Management Studio project.Exercise 2Creating a New DatabaseScenarioIn this exercise, you will create a new database using Graphic interface or a SQL Server Management Studio template. You will then investigate the default properties of a new database.TasksDetailed Steps1. Create a new database via Object Explorer1. Right click the Databases folder in the Object Explorer window and choose New Database item and then the New Database dialog pop up.2. Type the new Database Name “NewDB”, and then Click OK button, a new database will be created. 2. Create a new database using a TSQL Template.1. Choose View | Template Explorer.2. In the Template Explorer, expand the Database list.3. Double click on create database. If prompted, connect to the database.A new query window will open, and you should see the following template:- =- Create database template- =USE masterGO- Drop the database if it already existsIF EXISTS ( SELECT name FROM sys.databases WHERE name = N) DROP DATABASE GOCREATE DATABASE GO 4. Select the Edit | Find and Replace | Quick Replace menu command.5. In the Find what textbox, enter (including the angle brackets). Note that the Find and Replace dialog is not modal, so you can copy this text from the Query window and paste it into the Find what textbox. 6. In the Replace with textbox, enter NewDB.7. Click Replace All. A dialog box should show 3 occurrence(s) replaced. Click OK, and then close the dialog box.8. Press F5 or click the Execute button on the toolbar. Click Connect if necessary. Either select all of the text in the window and Execute or make sure you dont have something selected in the window and Execute.3. Explore your new database.1. In the Object Browser, expand Databases if necessary.2. Right-click on Databases and click Refresh. A NewDB folder should appear.3. Right-click on the NewDB folder and click Properties.4. Explore the properties dialog box to see what properties exist for a newly created database.Because the Properties window is not modal, you can open a separate Properties window for each database, making it easier to compare the two.5. Close the Properties window(s) when youre done.Exercise 3Attaching a DatabaseScenarioIn this exercise, you will attach the Northwind database using the “Attach Database” option in the SQL Server Management Studio Object Explorer.Attaching a database means making all the database files available to your SQL Server, just as if you had created the database on the current server. Detaching a database allows you to move the physical files and reattach those files from a new physical location, or to make a copy of the files to use on another server (perhaps a test or development server). Because the primary file contains the locations of all the other files in a database, if all the files are in their original location (as stored in the primary file) you only need to specify the primary file when attaching the database. SQL Server will read the information in the primary file and attach all the associated files for the database.However, if the files are not all in the original location, the information stored in the primary file may not be sufficient for SQL Server to find and attach all the database files. You will then need to specify the exact physical location of each database file that is not in the location it was when the database was detached. When a database is detached, SQL Server will do a checkpoint in the database, so all the committed transactions are written to the disk files. TasksDetailed Steps1. If the database is already attached, detach it.1. In the Object Explorer, expand localhost or the name of your server (if its not already expanded), then expand the Databases folders.2. If the Northwind database is in the list, right-click on it. Otherwise, skip to the Attach the Northwind database task below.3. Point to Tasks, and then click Detach. 4. In the Detach Database dialog box, click OK. If you did not close the script Window from Exercise 1, you will not be able to Detach the database and will get an error. Close the Window and retry the Detach process. 2. Attach the Northwind database.1. Copy SQL2000SampleDb.msi from our training share folder T-SQL Part2. Install it and default it would create folder in C:SQL Server 2000 Sample Databases path. 3. In the Object Explorer, right-click on the Databases folder, and click Attach. 4. In the Attach Databases dialog box, click Add.5. Locate and select the following master file for the Northwind database ( C:SQL Server 2000 Sample Databases Northwind.mdf), and click OK.6. Verify that there are two files listed in the Northwind database details section in the bottom half of the Attach Databases dialog box.7. Click OK to attach the database. 3. Use the Object Explorer to Verify the Northwind Database.1. Expand the Databases folder in the Object Explorer. 2. If the Northwind database doesnt appear, right-click the Databases folder and select Refresh.3. Expand the AdventureWorks database.4. Expand the Tables folder, and verify that there are several dozen tables.5. In the Solution Explorer, open the Queries folder under Exercise 2, and double click the file DatabaseProperties.sql. If requested, respond to the Connect to SQL Server dialog box.USE NorthwindSELECT DATABASEPROPERTYEX(Northwind, Status)SELECT DATABASEPROPERTYEX(Northwind, Recovery)SELECT DATABASEPROPERTYEX(Northwind, Collation)SELECT DATABASEPROPERTYEX(Northwind, Updateability)SELECT DATABASEPROPERTYEX(Northwind, UserAccess)SELECT DATABASEPROPERTYEX(Northwind, IsAutoCreateStatistics)SELECT DATABASEPROPERTYEX(Northwind, IsAutoShrink)6. Press F5 or click the Execute button on the toolbar to execute the batch7. Examine the values returned for the various database properties.Exercise 4Exploring DatabaseScenarioIn this exercise, you will use the options available in the SQL Server Management Studio to discover table and procedure definitions. You will also use the Management Studios query tool to execute basic SQL commands to examine table data. TasksDetailed Steps1. Examine the properties of the Northwind database.1. Expand the Databases folder in the Object Explorer window and right-click on the Northwind database.2. Click on Properties. Note that the Database Properties dialog box is non-modal and has its own button in the taskbar. You can see some propertied of Northwind database.3. Click on each of the categories in the left pane to see what properties are read-only and which are updateable.4. Click Cancel to close the Database Properties window.2. Modify Table to explore Tables Structure1. In the Object Explorer window, expand the Northwind Database folder and then expand Table node, you will see all of user tables in Northwind database.2. And right-click on dbo.Employees table, and choose Modify item, then you can explore the tables structure: Colunm name, Datatype and Allow Nulls property.3. Click on each row of the Column Grid, you can see the detailed property of each column in Column Properties window below.3. Open table to explore data1. In the Object Explorer window, expand the Northwind Database folder and then expand Table node, you will see all of user tables in Northwind database.2. And right-click on dbo.Employees table, and choose Open Table item, then you can explore the tables data.3. Following the step2, explore other tables data, too. Exercise 5Create Database ObjectsTables, ViewsScenarioSQL Management StudioIn this exercise, you will learn to create tables and views via SQL Server Management Studio.SQL Server 2005 Management Studio provides the graphic interface to create SQL Server objects. You can easily create database, tables, views, stored procedures or logins via SSMS. It also allows you to generate the SQL scripts from the exi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 四川立体绿化施工方案
- 装修方案范本流程表格
- 水电异常整改方案范本
- 风险投资项目汇报
- 期货从业资格考试高中及答案解析
- 职工责任考核方案范本
- 王林波荷叶圆圆教学课件
- 旧楼翻新电路施工方案
- 不锈钢板地面施工方案
- 证券从业专场考试杭州及答案解析
- 平面构成在服装设计中的运用
- 集团招商引资管理办法
- 2025年天文地理知识竞赛题库及答案
- 园区工作薪酬管理办法
- 劳动仲裁流程课件培训
- 睑腺炎的护理与治疗
- 2025至2030中国空气制水机行业市场发展分析及发展前景与投融资报告
- 公司礼仪培训课件
- 温州市2024-2025学年高一下学期期末英语测试卷
- 2025至2030年中国稀土储氢材料行业市场全景评估及发展趋向研判报告
- CD13在肝癌中的表达、作用机制及临床意义研究
评论
0/150
提交评论