SQL Server SQL 实用语句

感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!

id name
1 a
2 b
3 c
1 a
2 b
3 c

以下的sql语句都以上面表mytable为准:

1、查询id=1,3记录的所有数据

代码如下:


select * from mytable where id in(1,3) 

2、删除id重复的数据,表中数据只剩下id=1,2,3的所有数据

代码如下:


select * into # from mytable 
truncate table mytable 

insert table select distinct * from # 
select * from table 
drop table # 

3、创建一个新表 films_recent ,它的值包含来自表films

代码如下:


SELECT * INTO films_recent FROM films 

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...