![]() We want to pull information held in two separate tables out. Click and drag it off, right click it and select, “Add Related Tables”.īefore we move on, let’s think about what we want. The related table will drop right on top of the first table. Let’s right click on the Departments table and select, “Add Related Tables”. You’ll have a window that should look like the picture below. Scroll through and find the Departments table.Ĭlick, “Add” and then click, “Close. ![]() Click okay and once that’s done, you’ll get a window asking what table you want to diagram. It’ll ask to configure the database for diagrams. Let’s right click on Database Diagrams right above the tables. Many of my mathematics professors in college would say, when in doubt, draw a picture. What if we wanted to know what employees worked in what departments? Well, we need to figure out where the relationships lie within the database. A common example of this would be employees have departments and vice versa. Intuitively, a relational database is a technology that describes relationships between objects via one or more tables. Querying data out of a single table is a rare event. These queries work fine when we only need data out of a single table. To do so, let’s use the following query, “SELECT Name, GroupName FROM HumanResources.Department WHERE GroupName = ‘Executive General and Administration”. Let’s suppose we need the Departments under Executive General and Administration. To return precisely the number of rows you need, we will need use the WHERE clause in our query. In general, it just follows from a good principle of living, take only what you need and no more. There’s a lot of reasons for this, sometimes from a managing data perspective, other times from a server load perspective. Of course, it’s also best practice to only return the rows you need as well. To do so let’s type, “SELECT Name, GroupName FROM HumanResources.Department”. For example, let’s just return the Name and GroupName. It’s best practice to return only the columns you need. We can do this by typing out in the new query window, “SELECT * FROM HumanResources.Department”. Let’s start by just returning all rows and all columns from with HumanResources.Department. Right click on AdventureWorks2008RS and select, “New Query”. ![]() We can assume that this table models departments and divisions inside of the AdventureWorks organization. At that point, just type in “Constraints”, and you’ll find an entry constraints in the section on understanding tables. You may find the BOL entry by clicking, “Help” inside of SSMS and clicking, “search”. Constraints are quite important in databases, you can learn about them more here as well as in Books Online (BOL), the help built into SQL Server Management Studio (SSMS). In addition, we have a default constraint on the ModifiedDate column. In the above picture, we can observe that we have four columns titled, “DepartmentID”, “Name”, “GroupName”, and, “ModifiedDate”. The two features you’re likely to be most interested to start with are columns and constraints. If you expand a table, say HumanResources.Department, you find features that are appropriate to tables contained within. I have to assume some basic level of acquaintance with databases, but succinctly put, tables are to databases what tracks are to CDs (I wonder how long that analogy will last). You’ll see a number of tables within the database. Click the plus sign next to AdventureWorks2008R2. Let’s take a moment to explore our surroundings a little bit. Upon successful install, we were able to connect to our database server and expand the installed databases. In a previous post, we walked through installing SQL Server 2008 and the Adventure Works databases.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |