数据库

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

/*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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值