sql 修改列名及表名
代码如下:
EXEC sp_rename '表名.[原列名]', '新列名', 'column'
*************************************************************************
Transact-SQL 参考
sp_rename
更改当前数据库中用户创建对象(如表、列或用户定义数据类型)的名称。
示例
A. 重命名表
下例将表 customers 重命名为 custs。
EXEC sp_rename 'customers', 'custs'
B. 重命名列
下例将表 customers 中的列 contact title 重命名为 title。
EXEC sp_rename 'customers.[contact title]', 'title', 'COLUMN'
***********
而修改数据库名则用
sp_renamedb [ @dbname = ] 'old_name' , [ @newname = ] 'new_name'
相关文档:
Subquery: (single-row subqueries and multi-rows subqueries).
select select_list
from table
where expr operator (select select_list from table);
single-row subqueries operator: =, >, >=, <, <=, <>
e.g.:
1. select department_id, min(salary) from employees group by department_id ......
constraint Example:
1. grammer:
create table [schema.]table
(column datatype [DEFAULT expr]
[column_constraint], ...
[table_constraint] [,......]);
2. example of a column_level constraint:
create table empl ......
GRANT
Name
GRANT -- 定义访问权限
Synopsis GRANT { { SELECT | INSERT | UPDATE | DELETE | RULE | REFERENCES | TRIGGER }
[,...] | ALL [ PRIVILEGES ] }
ON [ TABLE ] tablename [, ...]
TO { username | GROUP groupname | PUBLIC } [, ...] [ WI ......
Merge statement
function benefits: 1) provides the ability to conditionally update, insert or delete data into a database table. 2) performs an update if the row exists, and an insert if it is a new row. --> 1) avoids seperate updates, 2) increase performance and ease of use. 3) is useful in dat ......
CREATE VIEW MYVIEW
AS
SELECT * from bjxxdiweb_database2007.dbo.bm_tongji
UNION ALL
SELECT * from aa.DBO.chen
select * into aa..chen from bjxxdiweb_database2007.dbo.bm_tongji where 1=2
说明:数据库A的表的字段名必须和数据库B的表的字段名相同,包括数据类型等。 ......