-- =============================================
-- ylb:系统函数
-- 13:45 2011/12/10
-- =============================================
use master
go
IF EXISTS (SELECT *
FROM master..sysdatabases
WHERE name = N'testData')
DROP DATABASE testData
GO
CREATE DATABASE testData
GO
use testData
go
-- =============================================
-- ylb:1,用户表
-- =============================================
create table users
(
userID int identity(100,1),
username varchar(20)
)
go
--@@identity
--返回上一插入标识的值
insert into users(username) values('sunshine')
insert into users(username) values('gaiZhen')
insert into users(username) values('yunPeng')
insert into users(username) values('guoHua')
go
select @@identity
go
--@@rowcount
--返回上一条语句影响的行数
select @@rowcount
go
--newID() 随机函数
select top 1 * from users
order by newID()
go
go
--sysdatabases 系统数据对象
select * from master..sysdatabases
go
--sysobjects 系统表对象
use testData
go
select * from sysobjects where xtype='U'
go
select * from testData..sysobjects
--P:查看表中的列和列的类型
go
use textData
go
select * from users
go
--不引用库直接查询
--P1:查看pubs的titles表
select * from pubs.dbo.titles
go
--动态从一个库中的表的数据插入另一个表中。
--P2:我想把pubs库中的authors中的名插入testData库中的
----users的username
select au_fname from pubs.dbo.authors
select * from testData.dbo.users
go
insert users(username) select au_fname from pubs.dbo.authors