第17课 创建和操纵表

创建表的方法:
1.多数DBMS都具有交互式创建和管理数据库表的工具;
2.表也可以直接用SQL语句操纵。
tips:对具体的DBMS支持何种语法,需要不同情况不同分析。
17.1.1表创建基础
利用CREATE TABLE创建表时,必须给出下列信息
(1)新表的名字,在关键字CREATE TABLE之后给出;
(2)表列的名字和定义,用逗号分隔;
(3)有的DBMS还要求指定表的位置。
创建的表:
在这里插入图片描述
相应的语法:表列的名字,表列数据的类型,NULL or Not NULL
1.每个表列要么是NULL列,要么是NOT NULL列(sql中不区分大小写),并且NULL为默认设置
2.只有不允许NULL值的列可以作为主键
在这里插入图片描述
往表格里添加值:

INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000001', 'Village Toys', '200 Maple Lane', 'Detroit', 'MI', '44444', 'USA', 'John Smith', 'sales@villagetoys.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES('1000000002', 'Kids Place', '333 South Lake Drive', 'Columbus', 'OH', '43333', 'USA', 'Michelle Green');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000003', 'Fun4All', '1 Sunny Place', 'Muncie', 'IN', '42222', 'USA', 'Jim Jones', 'jjones@fun4all.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000004', 'Fun4All', '829 Riverside Drive', 'Phoenix', 'AZ', '88888', 'USA', 'Denise L. Stephens', 'dstephens@fun4all.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES('1000000005', 'The Toy Store', '4545 53rd Street', 'Chicago', 'IL', '54545', 'USA', 'Kim Howard');

前面的字符串cust_email过长,导致了在shell中的观感非常不好
在这里插入图片描述
在这里插入图片描述
?想要将缺失值的情况筛选出来
WHERE cust_email is not NULL( is NULL)
在这里插入图片描述
17.3删除表
非必要,不使用,谨慎谨慎。

DROP TABEL table_name

CREATE TABLE 用来创建新表
ALTER TABLE 用来更改表列(或其他诸如约束或索引等对象),DROP TABLE用来完整地删除一个表。这些语句必须小心使用,并且应该在备份后使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值