sql 基础知识

基础知识:

创建表:create table A (........);

查询记录:select * from A

更新记录:update A set a.x=y where a.z=c

插入记录: insert into A(x,y,z) values(......);

删除某记录:delete [form] A where a.x =y [如果删除整表数据则不用条件]

删除表:drop table A

清空整表数据: truncate table A [有外键关联则不能单独清空数据]

1。使查询出来的数据不重复:

select distinct 字段名 from 表名

2。查询出重复的数据:

select 字段名 from 表名 group by 字段名 having count(字段名)>1

3。从其他表中获取数据建立表

CREATE TABLE table1 AS SELECT * FROM table2

4。增加列

ALTER TABLE [schema.] table_name ADD column_definition column_type

5。更改列

ALTER TABLE [schema.] table_name MODIFY (column_name column_type, newcolumn_name newcolumn_type)

6。更改表名

RENAME old_name TO new_name

7.连表查询

1)查出来的数据有重复

select * from A, B where A.x = B.x and B.x=y

2)查出来的数据没重复(子查询)

select * from A where A.x in(select * from B where B.x =y)

8.修改表的所有者

sp_MSForEachTable ’sp_changeobjectowner ’’?’’,’’dbo’’’

9.关联更新:

MySQL:update A a,B b set a.x=b.x where a.z=b.z

SQL2000:update a set a.x=b.x from A a,B b where a.z=b.z
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值