Inserttt
Inserttt
Inserttt
Introduct
II. Theorary
1. What is a database?
+ These can be used for local assessment and how to trear a particular disease and how to
improve patient health
+ Database can be used to study about epidemiological studies of disease particularly for
a disease as to which it spreads and also decreasing the particular emerging disease.
+ These database is also used for the Medicare provider Analysis and review database
and also for national rurvery.
+ These database about particular disease is to increase knowledge about that disease and
also forms the care and ciricullam plans about that disease
+ Types of databases
There are many different types of databases. The best database for a specific organization
depends on how the organization intends to use the data.
Relational databases
Relational databases became dominant in the 1980s. Items in a relational database
are organized as a set of tables with columns and rows. Relational database
technology provides the most efficient and flexible way to access structured
information.
Object-oriented databases
Information in an object-oriented database is represented in the form of objects, as
in object-oriented programming.
Distributed databases
A distributed database consists of two or more files located in different sites. The
database may be stored on multiple computers, located in the same physical
location, or scattered over different networks.
Data warehouses
A central repository for data, a data warehouse is a type of database specifically
designed for fast query and analysis.
NoSQL databases
A NoSQL, or nonrelational database, allows unstructured and semistructured data
to be stored and manipulated (in contrast to a relational database, which defines
how all data inserted into the database must be composed). NoSQL databases grew
popular as web applications became more common and more complex.
Graph databases
A graph database stores data in terms of entities and the relationships between
entities.
OLTP databases. An OLTP database is a speedy, analytic database designed for
large numbers of transactions performed by multiple users.
These are only a few of the several dozen types of databases in use today. Other, less
common databases are tailored to very specific scientific, financial, or other functions. In
addition to the different database types, changes in technology development approaches
and dramatic advances such as the cloud and automation are propelling databases in
entirely new directions. Some of the latest databases include
Open source databases
An open source database system is one whose source code is open source; such
databases could be SQL or NoSQL databases.
Cloud databases
A cloud database is a collection of data, either structured or unstructured, that
resides on a private, public, or hybrid cloud computing platform. There are two
types of cloud database models: traditional and database as a service (DBaaS).
With DBaaS, administrative tasks and maintenance are performed by a service
provider.
Multimodel database
Multimodel databases combine different types of database models into a single,
integrated back end. This means they can accommodate various data types.
Document/JSON database
Designed for storing, retrieving, and managing document-oriented
information, document databases are a modern way to store data in JSON format
rather than rows and columns.
Self-driving databases
The newest and most groundbreaking type of database, self-driving databases (also
known as autonomous databases) are cloud-based and use machine learning to
automate database tuning, security, backups, updates, and other routine
management tasks traditionally performed by database administrators.
By convention, all public properties with a getter and a setter will be included in the
model.
Data Annotations
Fluent API
C#Copy
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
[NotMapped]
public DateTime LoadedFromDatabase { get; set; }
}
Column names
By convention, when using a relational database, entity properties are mapped to table
columns having the same name as the property.
If you prefer to configure your columns with different names, you can do so as following
code snippet:
Data Annotations
Fluent API
C#Copy
public class Blog
{
[Column("blog_id")]
public int BlogId { get; set; }
When using a relational database, the database provider selects a data type based on
the .NET type of the property. It also takes into account other metadata, such as the
configured maximum length, whether the property is part of a primary key, etc.
You can also configure your columns to specify an exact data type for a column. For
example, the following code configures Url as a non-unicode string with maximum
length of 200 and Rating as decimal with precision of 5 and scale of 2:
Data Annotations
Fluent API
C#Copy
public class Blog
{
public int BlogId { get; set; }
[Column(TypeName = "varchar(200)")]
public string Url { get; set; }
Configuring a maximum length provides a hint to the database provider about the
appropriate column data type to choose for a given property. Maximum length only
applies to array data types, such as string and byte[].
Note
Entity Framework does not do any validation of maximum length before passing data to
the provider. It is up to the provider or data store to validate if appropriate. For example,
when targeting SQL Server, exceeding the maximum length will result in an exception as
the data type of the underlying column will not allow excess data to be stored.
In the following example, configuring a maximum length of 500 will cause a column of
type nvarchar(500) to be created on SQL Server:
Data Annotations
Fluent API
C#Copy
public class Blog
{
public int BlogId { get; set; }
[MaxLength(500)]
public string Url { get; set; }
}
Precision and Scale
Some relational data types support the precision and scale facets; these control what
values can be stored, and how much storage is needed for the column. Which data types
support precision and scale is database-dependent, but in most
databases decimal and DateTime types do support these facets. For decimal properties,
precision defines the maximum number of digits needed to express any value the column
will contain, and scale defines the maximum number of decimal places needed.
For DateTime properties, precision defines the maximum number of digits needed to
express fractions of seconds, and scale is not used.
Note
Entity Framework does not do any validation of precision or scale before passing data to
the provider. It is up to the provider or data store to validate as appropriate. For example,
when targeting SQL Server, a column of data type datetime does not allow the precision
to be set, whereas a datetime2 one can have precision between 0 and 7 inclusive.
The Data Annotation for configuring precision and scale was introduced in EF Core 6.0.
C#Copy
public class Blog
{
public int BlogId { get; set; }
[Precision(14, 2)]
public decimal Score { get; set; }
[Precision(3)]
public DateTime LastUpdated { get; set; }
}
Scale is never defined without first defining precision, so the Data Annotation for
defining the scale is [Precision(precision, scale)].
Unicode
In some relational databases, different types exist to represent Unicode and non-Unicode
text data. For example, in SQL Server, nvarchar(x) is used to represent Unicode data in
UTF-16, while varchar(x) is used to represent non-Unicode data (but see the notes
on SQL Server UTF-8 support). For databases which don't support this concept,
configuring this has no effect.
Text properties are configured as Unicode by default. You can configure a column as
non-Unicode as follows:
Data Annotations
Fluent API
Note
The Data Annotation for configuring Unicode was introduced in EF Core 6.0.
C#Copy
public class Book
{
public int Id { get; set; }
public string Title { get; set; }
[Unicode(false)]
[MaxLength(22)]
public string Isbn { get; set; }
}
Required and optional properties
Conventions
By convention, a property whose .NET type can contain null will be configured as
optional, whereas properties whose .NET type cannot contain null will be configured as
required. For example, all properties with .NET value types (int, decimal, bool, etc.) are
configured as required, and all properties with nullable .NET value types
(int?, decimal?, bool?, etc.) are configured as optional.
If nullable reference types are disabled, all properties with .NET reference
types are configured as optional by convention (for example, string).
If nullable reference types are enabled, properties will be configured based
on the C# nullability of their .NET type: string? will be configured as
optional, but string will be configured as required.
The following example shows an entity type with required and optional properties, with
the nullable reference feature disabled and enabled:
[Required]
public string LastName { get; set; } // Data annotations needed to configure as required
Using nullable reference types is recommended since it flows the nullability expressed in
C# code to EF Core's model and to the database, and obviates the use of the Fluent API
or Data Annotations to express the same concept twice.
Note
Exercise caution when enabling nullable reference types on an existing project: reference
type properties which were previously configured as optional will now be configured as
required, unless they are explicitly annotated to be nullable. When managing a relational
database schema, this may cause migrations to be generated which alter the database
column's nullability.
For more information on nullable reference types and how to use them with EF Core, see
the dedicated documentation page for this feature.
Explicit configuration
Data Annotations
Fluent API
C#Copy
public class Blog
{
public int BlogId { get; set; }
[Required]
public string Url { get; set; }
}
Column collations
Note
This feature was introduced in EF Core 5.0.
A collation can be defined on text columns, determining how they are compared and
ordered. For example, the following code snippet configures a SQL Server column to be
case-insensitive:
C#Copy
modelBuilder.Entity<Customer>().Property(c => c.Name)
.UseCollation("SQL_Latin1_General_CP1_CI_AS");
If all columns in a database need to use a certain collation, define the collation at the
database level instead.
General information about EF Core support for collations can be found in the collation
documentation page.
Column comments
You can set an arbitrary text comment that gets set on the database column, allowing you
to document your schema in the database:
Data Annotations
Fluent API
Note
C#Copy
public class Blog
{
public int BlogId { get; set; }
Data Annotations
Fluent API
C#Copy
public class EntityBase
{
[Column(Order = 0)]
public int Id { get; set; }
}
[Column(Order = 2)]
public string LastName { get; set; }
}
The Fluent API can be used to override ordering made with attributes, including
resolving any conflicts when attributes on different properties specify the same order
number.
4. Relational schema
- In databases, relational schema may refer to:
+ A (single) relation schema.
* Add the primary keys of all participating Entities as fields of table with
their respective data types.
You can interact with any relational database management system by using the SQL
programming language. SQL stands for “Structured Query Language”, which allows you
to interrogate structured data stored in tables.
Do not use multiple fields in a single table to store similar data. For example, to track an
inventory item that may come from two possible sources, an inventory record may
contain fields for Vendor Code 1 and Vendor Code 2.
What happens when you add a third vendor? Adding a field is not the answer; it requires
program and table modifications and does not smoothly accommodate a dynamic number
of vendors. Instead, place all vendor information in a separate table called Vendors, then
link inventory to vendors with an item number key, or vendors to inventory with a vendor
code key.
Create separate tables for sets of values that apply to multiple records.
Relate these tables with a foreign key.
Records should not depend on anything other than a table's primary key (a compound
key, if necessary). For example, consider a customer's address in an accounting system.
The address is needed by the Customers table, but also by the Orders, Shipping, Invoices,
Accounts Receivable, and Collections tables. Instead of storing the customer's address as
a separate entry in each of these tables, store it in one place, either in the Customers table
or in a separate Addresses table.
Values in a record that are not part of that record's key do not belong in the table. In
general, anytime the contents of a group of fields may apply to more than a single record
in the table, consider placing those fields in a separate table.
EXCEPTION: Adhering to the third normal form, while theoretically desirable, is not
always practical. If you have a Customers table and you want to eliminate all possible
interfield dependencies, you must create separate tables for cities, ZIP codes, sales
representatives, customer classes, and any other factor that may be duplicated in multiple
records. In theory, normalization is worth pursing. However, many small tables may
degrade performance or exceed open file and memory capacities.
It may be more feasible to apply third normal form only to data that changes frequently.
If some dependent fields remain, design your application to require the user to verify all
related fields when any one is changed.
Fourth normal form, also called Boyce Codd Normal Form (BCNF), and fifth normal
form do exist, but are rarely considered in practical design. Disregarding these rules may
result in less than perfect database design, but should not affect functionality.
*Unnormalized table:
Student# Advisor Adv-Room Class1 Class2 Class3
1022 Jones 412 101-07 143-01 159-02
4123 Smith 216 101-07 143-01 179-04
Tables should have only two dimensions. Since one student has several classes, these
classes should be listed in a separate table. Fields Class1, Class2, and Class3 in the above
records are indications of design trouble.
Spreadsheets often use the third dimension, but tables should not. Another way to look at
this problem is with a one-to-many relationship, do not put the one side and the many
side in the same table. Instead, create another table in first normal form by eliminating
the repeating group (Class#), as shown below:
Note the multiple Class# values for each Student# value in the above table. Class# is not
functionally dependent on Student# (primary key), so this relationship is not in second
normal form.
Students:
Registration:
Student# Class#
1022 101-07
1022 143-01
Student# Class#
1022 159-02
4123 101-07
4123 143-01
4123 179-04
In the last example, Adv-Room (the advisor's office number) is functionally dependent on
the Advisor attribute. The solution is to move that attribute from the Students table to the
Faculty table, as shown below:
Students:
Student# Advisor
1022 Jones
4123 Smith
Name Room Dept
Jones 412 42
Smith 216 42
Faculty:
7. Query language
- Query language (QL) refers to any computer programming language that requests and
retrieves data from database and information systems by sending queries. It works on
user entered structured and formal programming command based queries to find and
extract data from host databases.
The following is a list of commonly used SQL commands that can be used to
create tables, insert data, change the structure of the tables, and query the data.
CREATE
The CREATE statement is used to create tables in a database. The statement can define
the field names and field data types within a table. The CREATE statement is also used
to define the unique identities of the table using primary key constraints. It is also used to
describe the relationships between tables by defining a foreign key.
Template:
Column_1 Datatype1,
Column_2 Datatype2..
);
ALTER
The ALTER statement is used to change the structure of a table in the database. The
statement can be used to create a new column or change the data type of an existing
column.
Template:
DROP
The DROP statement is used to delete a table from a database. It must be used with
caution as deletion is irreversible.
Template:
INSERT
The INSERT statement is used to add records or rows to a table. The name of the table to
insert records into is defined first. Then, the column names within the table are defined.
Finally, the values of the records are defined to insert into these columns.
Template:
VALUES (Value_1,…,Value_N)
UPDATE
The UPDATE statement is used to modify records in a table. The statement changes the
values of a specified subset of records held in the defined columns of the table. It is a
good practice to filter rows using a WHERE clause when updating records. Otherwise, all
records will be altered by the UPDATE statement.
Template:
UPDATE [tableName]
DELETE
The DELETE statement is used to delete rows from a table based on criteria defined
using a WHERE clause. The statement should be used carefully, as all deletion in a
database is permanent. If a mistake is made using a DELETE statement, the database will
need to be restored from a backup.
Template:
8. System testing
- System testing is the testing of a complete and fully integrated product. After
Integration test and Unit test
- After completing the integration testing process we need to further check the
compatibility and interact with the external peripherals of the application to check its
usability.
III. Practice
- To make a 2-hand clothing sales system, we need first an admin to manage the entire
store system. Then we need to put products with high quality into the store to improve
the reputation. When a customer buys a product, it will include price, size, .. and more
forms of payment. Finally, at step 1, we pay and ship to customer 2, who are direct
buyers.