Hua Gong retries and study notes, Hua Gong Study Notes
Today is July 22, March 10, and there are 5 days before the review of the Chinese site. the Retest is performed on the database, and the questions are given by VS and SQL server. difficult. below are my notes for testing the machine.
I. Database Design
Create index <index-name> on <relation-name> (<attribute-list>)
Example: create index dept-index on policuctor (dept_name)
Create view v as <query-expression>
Example: create view faulty
Select ID, name, dept_name
From instructor
Default 0
Check (P) // P is the condition
For example, check (size <10) // only records with a size smaller than 10 can be inserted.
Foreign key (dept_name) references department
On delete cascade
On update cascade
SELECT field FROM table WHERE a field Like Condition
Condition:
① %: 0 or more characters.
② _: Represents any single character.
③ []: Indicates one of the characters listed in brackets (similar to regular expressions ).
④ [^]: A single character not listed in parentheses.
⑤ When the query content contains wildcards: use [] to enclose special characters.
Ii. Database Programming
Server = <IP>; Database = <Database Name>; Integrated Security = false; Uid = <Login Name>; Pwd = <password>
Server = (local); Database = <Database Name>; Integrated Security = sspi
Public static void ExecuteNoQuery (string SQL)
{
Try
{
SqlCommand cmd = new SqlCommad (SQL, SqlUtil. conn );
If (cmd. ExcuteNoQuery ()> 0)
{
MessageBox. Show ("operation successful ");
}
Else
{
MessageBox. Show ("Operation failed ");
}
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message );
}
}
Public static DataTable ExecuteQuery (string SQL)
{
Try
{
DataTable table = new DataTable ();
DataAdapter adapter = new DataAdapter (SQL, SqlUtil. conn );
Adapter. Fill (table );
Return table;
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message );
Return null;
}
}
Try
{
SqlConnection conn = new SqlConnection (SqlUtil. connstr );
Conn. Open ();
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message );
Applitcation. Exit ();
Return;
}
SqlUtil. conn. Close (); // do not use Dispose () because the connection resources will be recycled.
DataGridView1.DataSource = table;
SelectedIndexChanged
This. dataGridView1.SelectedRows [0]. Cell [0]. Value;
DataGridView1.Rows. RemoveAt (maid [0]. index );
DataGridView1.SelectionMode = maid mode. FullRowSelect;
DataGridView1.ReadOnly = true;
DialogResult dr = MessageBox. Show (this, "are you sure you want to delete ?"," Prompt ", MessageBoxButton. YesNO );
If (dr = DialogResult. Yes) // The code after clicking OK
Activated
Private void refresh ()
{
String SQL = "select * from <Table Name> ";
DataTable table = SqlUtil. ExecuteQuery (SQL );
DataGridView1.DataSource = table;
}