Use the Management Studio to create the following tables and relationships in th
ID: 3749147 • Letter: U
Question
Use the Management Studio to create the following tables and relationships in the Membership database. Define IndividualID and GroupID as IDENTITY columns. Allow Address and Phone to accept null values; none of the other columns should allow null values. Define the Dues column with a default of zero and a check constraint to allow only positive values. Define the DuesPaid column with a default Boolean value of False.
Use the Management Studio to index the GroupMembership table. Create a clustered index on the GroupID column, a nonclustered index on the IndividualID column, and a unique index and constraint on both columns.
Explanation / Answer
To create a new Windows-based application
In Visual Studio, on the File menu, point to New and then click Project.
Name the project SampleDatabaseWalkthrough.
Click Windows Forms Application and then click OK. For more information, see Developing Client Applications.
The SampleDatabaseWalkthrough project is created and added to Solution Explorer/Database Explorer.
Creating a New SQL Server Database
To add a new database to the project
On the Project menu, click Add New Item.
Select Local Database in the list of available templates.
Type SampleDatabase in the Name box.
Click Add.
The Data Source Configuration Wizard opens with the new SampleDatabase.sdf file chosen as the data connection.
Click Next.
Click Next again to save the connection string to the application configuration file.
Click Finish on the Choose Your Database Objects page. (No database objects are available because this is a new database.)
SampleDatabase.sdf and SampleDatabaseDataSet.xsd are added to the project.
Creating New Tables in the Database
To add tables to the database
Open Server Explorer/Database Explorer by clicking Server Explorer/Database Explorer on theViewmenu.
Expand the SampleDatabase.sdf node under the Data Connections node.
Right-click Tables and then click Create Table.
The New Table dialog box opens.
Create columns as described in the following table:
Column Name
Data Type
Length
Allow Nulls
CustomerID
nchar
5
No
CompanyName
nvarchar
40
No
ContactName
nvarchar
30
Yes
ContactTitle
nvarchar
30
Yes
Address
nvarchar
60
Yes
City
nvarchar
15
Yes
Region
nvarchar
15
Yes
PostalCode
nvarchar
10
Yes
Country
nvarchar
15
Yes
Phone
nvarchar
24
Yes
Fax
nvarchar
24
Yes
Select the CustomerID column, and then set Primary Key to Yes.
Type Customers in the Name box.
Click OK.
In Server Explorer/Database Explorer, right-click Tables and then click Create Table.
The New Table dialog box opens.
Create columns as described in the following table:
Column Name
Data Type
Length
Allow Nulls
OrderID
int
4
No
CustomerID
nchar
5
Yes
EmployeeID
int
4
Yes
OrderDate
datetime
8
Yes
RequiredDate
datetime
8
Yes
ShippedDate
datetime
8
Yes
ShipVia
int
4
Yes
Freight
money
19
Yes
ShipName
nvarchar
40
Yes
ShipAddress
nvarchar
60
Yes
ShipCity
nvarchar
15
Yes
ShipRegion
nvarchar
15
Yes
ShipPostalCode
nvarchar
10
Yes
ShipCountry
nvarchar
15
Yes
Select the OrderID column, and then set Primary Key to Yes.
Type Orders in the Name area.
Click OK.
Column Name
Data Type
Length
Allow Nulls
CustomerID
nchar
5
No
CompanyName
nvarchar
40
No
ContactName
nvarchar
30
Yes
ContactTitle
nvarchar
30
Yes
Address
nvarchar
60
Yes
City
nvarchar
15
Yes
Region
nvarchar
15
Yes
PostalCode
nvarchar
10
Yes
Country
nvarchar
15
Yes
Phone
nvarchar
24
Yes
Fax
nvarchar
24
Yes
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.