㈠ 我想知道在sql里如何查詢到資料庫的建立時間及每個表的建立時間
思路:
1、在MSSQL中有分別存儲資料庫和表的信息表
2、存儲資料庫信息的表為:sys.databases,它是對SQL Server 系統上的每個系統資料庫和用戶自定義的資料庫含有一行記錄,並且,它只出現在master資料庫中。
3、表的信息為:sys.tables,它是當前資料庫中的所有的表對象,包含所有表的信息。
實現代碼:
--1、資料庫信息
select*frommaster..sysdatabases
--2、表信息
use某某資料庫
go
select*fromsys.tables
延伸閱讀:
資料庫中系統表及用途
sysaltfiles:主資料庫 保存資料庫的文件
syscharsets:主資料庫字元集與排序順序
sysconfigures:主資料庫 配置選項
syscurconfigs:主資料庫當前配置選項
sysdatabases:主資料庫伺服器中的資料庫
syslanguages:主資料庫語言
syslogins:主資料庫 登陸帳號信息
sysoledbusers:主資料庫 鏈接伺服器登陸信息
sysprocesses:主資料庫進程
sysremotelogins主資料庫 遠程登錄帳號
syscolumns:每個資料庫 列
sysconstrains:每個資料庫 限制
sysfilegroups:每個資料庫 文件組
sysfiles:每個資料庫 文件
sysforeignkeys:每個資料庫 外部關鍵字
sysindexs:每個資料庫 索引
sysmenbers:每個資料庫角色成員
sysobjects:每個資料庫所有資料庫對象
syscomments:資料庫對象的詳細資料
syspermissio ns:每個資料庫 許可權
systypes:每個資料庫 用戶定義數據類型
sysusers:每個資料庫 用戶
㈡ 如何查看資料庫表空間的創建sql語句
最直觀的方法就是直接在pl/sql里查看 命令行如下
查看所有用戶:select * from all_users;
查看錶空間:select tablespace_name from dba_tablespaces;
查看用戶具有怎樣的角色:select * from dba_role_privs where grantee='用戶名';
查看某個角色包括哪些系統許可權:select * from dba_sys_privs where grantee='DBA'
查看oracle中所有的角色:select * from dba_roles;
㈢ C# 創建SQL資料庫 如何判斷資料庫是否創建完成。
你可以在創建後就try嘛,不成功的話就sleep,接著try,直到成功!
就算你判斷創建過程是否完成也需要重復的try啊!
㈣ 在sql中怎麼查看已經建立好的表
你是不是使用SQL語言寫了一個創建表的語句呢,比如:
create table student(id int primary key,name varchar(50),age varchar(2))
然後執行成功以後,找不到表在哪裡了。如果是這樣的話,可以通過下面的方法來找:
非圖形界面:show database; use database;show tables;找到「student」
圖形界面:找到左邊的tables標簽,然後找到你的表名「student」
㈤ sqllitedatabase 表是否創建成功為什麼存不進去數據呢
insert方法發出來看看。算了,估計也看不明白,這里給你一個有用的
調用方法是 try
{
DataBaseController.getInstance(Launcher2.this).insertOrUpdateRadio(info);
}
catch (Exception e)
{
e.printStackTrace();
}
以下為資料庫類的代碼,我是也是拿別的項目改的。里邊注釋掉的方法語句是對的,如果你有需要可以改成你所需要的欄位應該就可以使用。沒注釋的方法就是我改好了我自己要用的。
package com.android.luancher.database;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.android.common.Constant;
public class DataBaseController
{
private static final String TAG = "DataBaseService";
private final static byte[] writeLock = new byte[0];
private DatabaseHelper mDHelper;
private Context mCtxt;
private SQLiteDatabase db = null;
private static final String DATABASE_activityName = "launcher_workspace_apps.db";// TABLE
// IF
private String DB_PATH = "/data/data/com.android.launcher/databases/" + DATABASE_activityName;
private static final int VERSION = 1;
private static final String SQL_CREATE_TABLE_WORKSPACE_APPS = "CREATE TABLE IF NOT EXISTS table_workspace_apps("
+ "position INTEGER," + "activityName TEXT," + "packageName TEXT" + ");";
private DataBaseController(Context context)
{
this.mCtxt = context;
mDHelper = new DatabaseHelper(mCtxt);
}
static private DataBaseController dbService;
public static DataBaseController getInstance(Context context)
{
if (dbService == null)
{
dbService = new DataBaseController(context);
}
return dbService;
}
public void close()
{
Log.v(TAG, "closeDB()");
db.close();
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_activityName, null, VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
Log.d(TAG, "DatabaseHelper onCreate DB");
db.execSQL(SQL_CREATE_TABLE_WORKSPACE_APPS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.i(TAG, "updatgeDatabase: drop Table table_workspace_apps");
db.execSQL("DROP TABLE IF EXISTS table_workspace_apps");
onCreate(db);
}
}
// 插入或更新
public boolean insertOrUpdateRadio(AppInfo info)
throws Exception
{
synchronized (writeLock)
{
db = mDHelper.getWritableDatabase();
boolean result = true;
ContentValues ctV = new ContentValues();
ctV.put("position", info.position);
ctV.put("activityName", info.activityName);
ctV.put("packageName", info.packageName);
if (info.position == -1 || this.getAppBean(info.position) == null)
{
Log.d(TAG, "insert activityName: " + info.activityName);
db.insertOrThrow("table_workspace_apps", null, ctV);
}
else
{
Log.d(TAG, "UPDATE activityName: " + info.activityName);
db.update("table_workspace_apps", ctV, "position=" + info.position, null);
}
return result;
}
}
public AppInfo getAppBean(int position)
throws Exception
{
synchronized (writeLock)
{
db = mDHelper.getWritableDatabase();
AppInfo info = null;
// SQLiteDatabase db = openDB();
if (position > 0)
{
Cursor c = db.query("table_workspace_apps", null, "position=" + position, null, null, null, null);
if (c.moveToFirst())
{
info = cur2AppInfo(c);
}
c.close();
}
return info;
}
}
// public Radio getRadioByPostion(int position)
// {
// synchronized (writeLock)
// {
// db = mDHelper.getWritableDatabase();
// Radio ret = null;
// // SQLiteDatabase db = openDB(); "type=" + type + int type,
// Log.v(TAG, "db" + db);
// if (position > 0)
// {
// Cursor c = db.query("table_workspace_apps", null, " position=" + position, null, null, null, null);
// if (c.moveToFirst())
// {
// ret = cur2AppInfo(c);
//
// }
// c.close();
// }
//
// return ret;
// }
// }
// public Radio getRadioBypackgeactivityName(int packgeactivityName)
// {
// synchronized (writeLock)
// {
// db = mDHelper.getWritableDatabase();
// Radio ret = null;
// // SQLiteDatabase db = openDB(); "type=" + type + int type,
// Log.v(TAG, "db" + db);
// if (packgeactivityName >= 0)
// {
// Cursor c =
// db.query("table_workspace_apps",
// null,
// " packgeactivityName=" + packgeactivityName,
// null,
// null,
// null,
// null);
// if (c.moveToFirst())
// {
// ret = cur2AppInfo(c);
//
// }
// c.close();
// }
//
// return ret;
// }
// }
public ArrayList<AppInfo> getAppInfoList()
{
synchronized (writeLock)
{
db = mDHelper.getWritableDatabase();
ArrayList<AppInfo> lst = new ArrayList<AppInfo>();
Cursor cur =
db.query("table_workspace_apps",
new String[] {"position","activityName", "packageName"},
null,
null,
null,
null,
" position asc");// " position asc"
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext())
{
AppInfo info = cur2AppInfo(cur);
lst.add(info);
}
cur.close();
return lst;
}
}
// public Radio getRadioByType(int freq)
// {
// synchronized (writeLock)
// {
// db = mDHelper.getWritableDatabase();
// Radio ret = new Radio();
// Cursor cur =
// db.query("table_workspace_apps", new String[] {"id", "activityName", "freq", "desp", "type",
// "packgeactivityName", "position"}, "freq=" + freq, null, null, null, " position asc");
// if (cur.moveToFirst())
// {
// ret = cur2AppInfo(cur);
// Log.v("getRadioByType", "retret:" + ret.freq);
// }
// cur.close();
//
// return ret;
// }
//
// }
// 刪除指定位置的快捷方式
public void deleteByPosition(int position)
{
synchronized (writeLock)
{
db = mDHelper.getWritableDatabase();
// SQLiteDatabase db = openDB();
db.delete("table_workspace_apps", "position=" + position, null);
}
}
// 根據包名和類名刪除快捷方式
public void deleteInfo(String activityName, String packageName)
{
synchronized (writeLock)
{
db = mDHelper.getWritableDatabase();
// SQLiteDatabase db = openDB();
db.delete("table_workspace_apps", "activityName=" + activityName + " and packageName=" + packageName, null);
}
}
public boolean updatepackgeactivityName(int lastFreq)
{
synchronized (writeLock)
{
db = mDHelper.getWritableDatabase();
String sql = "update table_workspace_apps set packgeactivityName=0 where freq=" + lastFreq;
try
{
db.execSQL(sql);
return true;
}
catch (SQLException ex)
{
Log.v("ConnDBHelper", "updatePosition Error");
return false;
}
}
}
private AppInfo cur2AppInfo(Cursor c)
{
AppInfo info = new AppInfo();
info.position = c.getInt(0);
info.activityName = c.getString(1);
info.packageName = c.getString(2);
return info;
}
}