常用SQL語句

2021-09-05 09:20:32 字數 4220 閱讀 6290

sql server 跨庫連線插入:

insert  into 本地表

select *

from openrowset('sqloledb ','172.16.50.40'; 'sa'; 'password', db.dbo.遠端表);

sql server 複製表:

select * into 新錶 from 舊表
sql server 複製表結構:

select * into 新錶 from 舊表 where 1 = 2
sql server 遠端表匯入本地表:

select * into 本地表 from openrowset( 'sqloledb ', '172.16.50.40'; 'sa'; 'password', db(遠端資料庫).dbo.遠端表)
oracle 建選單:

select t.rowid,t.* from ssp_page_menu t where t.show_name like '%%'

select t.rowid,t.* from ssp_page_menu t where t.menu_level like '%'

--加密煉手持的時候先加密煉手持選單和許可權,再加後工序平台選單和許可權(ssp_page_action中的bakup_flag為密煉syspageaction中該選單的許可權objid)

bakup_time from ssp_page_action t where page_menu_id = ''

oracle 建表及主鍵自增

-- create table

create table psm_fix_main

( objid number(10) not null,

tyre_no number(20),

tyre_backno number(20),

material_id number(20),

erpcode varchar2(20),

out_level varchar2(20),

back_level varchar2(20),

out_date date,

back_date date,

record_time date,

record_user varchar2(20),

bugs varchar2(20)

)tablespace mesdb_data

pctfree 10

initrans 1

maxtrans 255

storage

( initial 16

next 8

minextents 1

maxextents unlimited

);-- add comments to the columns

comment on column psm_fix_main.tyre_no

is '外修胎號';

comment on column psm_fix_main.tyre_backno

is '回歸胎號';

comment on column psm_fix_main.material_id

is '物料id';

comment on column psm_fix_main.erpcode

is 'erp編碼';

comment on column psm_fix_main.out_level

is '外修品級';

comment on column psm_fix_main.back_level

is '回歸品級';

comment on column psm_fix_main.out_date

is '外修時間';

comment on column psm_fix_main.back_date

is '回歸時間';

comment on column psm_fix_main.record_time

is '記錄時間';

comment on column psm_fix_main.record_user

is '記錄人';

comment on column psm_fix_main.bugs

is '病疵';

-- create/recreate primary, unique and foreign key constraints

alter table psm_fix_main

add constraint psm_fix_main primary key (objid)

using index

tablespace mesdb_data

pctfree 10

initrans 2

maxtrans 255

storage

( initial 64k

next 1m

minextents 1

maxextents unlimited

);create sequence seq_psm_fix_main_autoinc

minvalue 1

maxvalue 9999999999999999999999999999

start with 1

increment by 1

nocache;

create or replace trigger insert_psm_fix_main_autoinc

before insert on psm_fix_main

for each row

begin

select seq_psm_fix_main_autoinc.nextval into :new.objid from dual;

end;

sql常用sql語句

1 查詢某個庫中所有的表名字 select name from sysobjects where xtype u and name dtproperties order by name 2 得到資料庫中所有使用者檢視 select name from sysobjects where xtype v...

常用sql語句

t sql語句複製表的方法 我在sql server 2000中有現個資料庫datahr及demo,它們的結構是一樣,其它有乙個表名為 gbitem.現在我想將demo資料庫的表名 gbitem的全部內容複製到datahr資料庫的表名為 gbitem中。請問此t sql語句應該怎麼寫?謝謝高人指點!...

常用SQL語句

查詢 sp who 中的結果值。因為儲存過程不能查詢,先轉為臨時表再查詢。declare tb table spid varchar 100 ecid varchar 100 status varchar 100 loginame varchar 100 hostname varchar 100 b...