数据库

/*****************************************/
/*创建数据表格过程*/
/*****************************************/

/*Phase 1*/
use test;
create table customer(
    customer_id int,
    customer_name char(20),
    customer_street char(30),
    customer_city char(30),
    primary key(customer_id)
);

/*下面是针对MySQL相关的应用内容*/
/*Phase 2*/
create table test.branch(
    branch_id int,
    branch_name char(15),
    branch_city char(30),
    assets  numeric(16,2),
    primary key(branch_id)
);

/*Phase 3*/
create table test.account(
    account_id int,
    account_number char(10),
    account_name char(15),
    balance numeric(12,2),
    primary key(account_id)
);
/*Phase 4*/
create table test.depositor(
    customer_id int,
    customer_name char(20),
    customer_number char(10),
    primary key(customer_id)
);


/*Test 1
    测试create建表和delete销毁
*/
/*Step 1*/
create table test.testTable(
    id int,
    name char(20),
    primary key(id)
);

/*Step 2*/
/*下面两种方式是一样的,也即,MySQL不区分大小写*/
insert into test.testTable values(1, "boss");
/*insert into test.testtable values(1, "boss");*/

/*Step 3*/
-- 获取表内数据
select * from test.testTable;

/*Step 4*/
-- 删除表格及其表格内部关系
drop table test.testTable;

/*Step 5*/
/*这里需要对MySQL的删除更新做相应的设置
错误提示如下:
0	21:38:10	delete from test.testTable	Error Code: 1175. 
You are using safe update mode and you tried to update a table
without a WHERE that uses a KEY column To disable safe mode,
toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect.
*/
SET SQL_SAFE_UPDATES = 0;
-- 删除表格内容
delete from test.testTable;



/*测试alter table r add A D*/
# Step 1
create table test.alterTable(
    T_id int,
    T_name char(30),
    primary key(T_id)
);

#注意创建过程需要时间,因此插入过程需要停等。

# Step 2
insert into test.alterTable values(1, "Boy", "boy");

# Step 3
select * from test.alterTable;

# Step 4
drop table test.alterTable;

# Step 5
-- 添加一列
alter table test.alterTable add sex char(10);

# Step 6
-- 查询结果
select * from test.alterTable;

# Step 7
-- 添加数据
insert into test.alterTable values(1, "Boy", "boy");
# Step 8
-- 查询结果
select * from test.alterTable;

# Step 9
-- 删除一列
alter table test.alterTable drop sex;


版权声明:本文为ying66feng原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。