database1
database1
• If a table contains one or more columns that uniquely identifies each row in the table, it is
defined as primary key of the table.
• Primary key consists of two or more columns. It is called a composite primary key.
• The only difference between unique key and primary key is that unique key contain null value
and a primary key can’t.
• An index provides and efficient way to access data from a table based on the values in
specific columns.
• Foreign key is one or more columns in a table that refer to a primary key in another table
• The data type that is assigned to a column determines the type of information that can be
stored in the column.
• Depending on the data type, the column definition can also include its length, precision and
scale.
• Each column definition also indicates whether or not the column can contain null values.
• A null value indicates that the value of the column is not known.
• A column can be defined with a default value. Then, that value is used for the column if
another value isn’t provided when a row is added to the table.
• An identity column is a numeric column whose value is generated automatically when a row
is added to the table.
• To restrict the values that a column can hold, use check constraints. It can be defined at the
column level or the table level.
SQL to work with data in database
• SQL statements which are used to manipulate the data in a database is Select, Insert, Update
and Delete.
• A result set is a logical table that is created temporarily within the database.
• A result set can include columns that are calculated from other columns in the table.
• To select all of the columns in a table use asterisk (*) in place of the column names.
• A join combine data from two or more tables in to a single result set.
• The most common type of join is an inner join. Inner join returns rows from both table only if
their related columns match.
• Insert, Update and Delete statements are used to add new rows to a table, to update the
data in existing rows and to delete existing rows.
•
Introduction to ADO.NET4
• ADO.NET 4(Active X Data Objects) is the primary data access API for the .net framework.
1.Datasets
• Data used by an application is stored in a dataset that contain one or more data tables.
• .NET data provider objects retrieve data from and update data in the database.
• The main function of the data adapter is to manage the flow of data between a data set and
a database.
Concurrency and the disconnected data architecture
Introduction to ADO.NET4 Classes
1. SqlConnection class
• A SqlCommand object is used to execute a SQL command against a SQL Server database
3.SqlParameter class
• A SqlParameter object is used to pass variable information to a SQL command. Used to limit
the no of rows returned by a select statement.
4 SqlDataReader class
• The SqlDataReader object is used to read a row of record at a time which is got using
SqlCommand.
• It is read only, which means we can only read the record; it can’t be edited.
• And also it is forward only, which means we can’t go back to a previous row (record)
5 SqlDataAdapter class
• The SqlDataAdapter works as a bridge between a DataSet and a data source (SQL Server
Database) to retrieve data.
• The SqlDataAdapter is a class that represents a set of SQL commands and a database
connection.
• It can be used to fill the DataSet and update the data source.