基础知识:
创建表: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
创建表: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