當前位置:首頁 » 操作系統 » 資料庫操作

資料庫操作

發布時間: 2022-01-10 23:01:07

資料庫操作

不知道你們使用的是什麼資料庫,如果是oracle資料庫要在本機訪問資料庫都是要用連接工具的,如果你是管理員能使用工具登陸資料庫,那就在工具裡面執行命令就行了,先要知道你要修改的資料庫裡面的表的名字,「select * from 表的名字」把表的名字換成你資料庫考勤表的名字(考勤數據一般是存放在考勤表裡面的),執行以下這個命令,就可以看到表裡面的數據了,然後你可以找到你姓名那一列,如果有你的名字,說明那條數據記錄的是你的考勤信息,「update 考勤表 set 上班時間 = '2010-12-12 08:55:55' where 姓名='你的名字'」,這段命令就能把你的上班時間改成'2010-12-12 08:55:55,當然了這個時間可以自己定,表的名字和時間這些東西要改成你資料庫裡面對應的名字,要不然會說你的表名或者列名無效,這兩個命令是所有資料庫都支持的,你可以到網上多學一些資料庫的知識,最好是找人教你怎麼搭建訪問資料庫的環境,其實資料庫就是一張一張的表,然後把輸入的信息存起來,等我們要用的時候把這些數據查詢出來,就像腦袋一樣可以記憶。

㈡ 如何使用資料庫

不知道你說的編寫資料庫登錄程序是什麼意思。
如果只是操作資料庫,一般是一下幾個步驟:
1、安裝資料庫軟體,比如mysql
2、在安裝的過程中,安裝程序就會提示你進行配置,一般是設置用戶名、密碼
3、下載資料庫查詢工具,其實就是個可視化的界面,如果你有自己的程序,只需要使用自己的系統操作資料庫,這個可以跳過。不過還是建議你下一個查詢工具,經常會用到。
4、打開查詢工具,輸入用戶名密碼,連接成功後,在打開的界面上寫sql腳本,執行。
5、如果沒有查詢工具,需要在你自己的程序里寫資料庫連接串,裡面也是些資料庫IP、名稱、用戶名、密碼等信息,然後使用自己所用的語言里提供的資料庫操作類進行連接。連上後,發送sql腳本語句進行操作。

㈢ sql資料庫的基本操作

命令行
1、顯示當前資料庫伺服器中的資料庫列表:mysql> SHOW DATABASES;
2、建立資料庫:mysql> CREATE DATABASE 庫名;
3、建立數據表:mysql> USE 庫名;mysql> CREATE TABLE 表名 (欄位名 VARCHAR(20), 欄位名 CHAR(1));
4、刪除資料庫:mysql> DROP DATABASE 庫名;
5、刪除數據表:mysql> DROP TABLE 表名;
6、將表中記錄清空:mysql> DELETE FROM 表名;
7、往表中插入記錄:mysql> INSERT INTO 表名 VALUES ("hyq","M");
8、更新表中數據:mysql-> UPDATE 表名 SET 欄位名1='a',欄位名2='b' WHERE 欄位名3='c';
9、用文本方式將數據裝入數據表中:mysql> load data local infile "d:/mysql.txt" into table 表名;
10、導入.sql文件命令:mysql> USE 資料庫名;mysql> source d:/mysql.sql;
11、命令行修改root密碼:mysql> update mysql.user set password=password('新密碼') where user='root';mysql> flush privileges;
12.修改密碼的三種方法:mysql>update user set password=password('123456') where user='joy_pen';mysql>flush privileges;mysql>set password for 'joy_oen'=password('123456');mysql>grant usage on *.* to 'joy_pen' identified by '123456';
1、創建資料庫
命令:create database <資料庫名> 例如:建立一個名為xhkdb的資料庫mysql> create database xhkdb;
2、顯示所有的資料庫
命令:show databases (注意:最後有個s)mysql> show databases;
3、刪除資料庫
命令:drop database <資料庫名> 例如:刪除名為 xhkdb的資料庫mysql> drop database xhkdb;
4、連接資料庫
命令: use <資料庫名> 例如:如果xhkdb資料庫存在,嘗試存取它:mysql> use xhkdb; 屏幕提示:Database changed
5、當前選擇(連接)的資料庫mysql> select database();
6、當前資料庫包含的表信息:mysql> show tables; (注意:最後有個s)
三、表操作,操作之前應連接某個資料庫
1、建表
命令:create table <表名> ( <欄位名1> <類型1> [,..<欄位名n> <類型n>]);
mysql> create table MyClass(
> id int(4) not null primary key auto_increment,
> name char(20) not null,
> sex int(4) not null default ''0'',
> degree double(16,2));
2、獲取表結構
命令: desc 表名,或者show columns from 表名
mysql>DESCRIBE MyClass
mysql> desc MyClass;
mysql> show columns from MyClass;
3、刪除表
命令:drop table <表名>
例如:刪除表名為 MyClass 的表 mysql> drop table MyClass;
4、插入數據
命令:insert into <表名> [( <欄位名1>[,..<欄位名n > ])] values ( 值1 )[, ( 值n )]
例如,往表 MyClass中插入二條記錄, 這二條記錄表示:編號為1的名為Tom的成績為96.45, 編號為2 的名為Joan 的成績為82.99,編號為3 的名為Wang 的成績為96.5.
mysql> insert into MyClass values(1,'Tom',96.45),(2,'Joan',82.99), (2,'Wang', 96.59);
5、查詢表中的數據
1)、查詢所有行
命令: select <欄位1,欄位2,...> from < 表名 > where < 表達式 >
例如:查看錶 MyClass 中所有數據 mysql> select * from MyClass;
2)、查詢前幾行數據
例如:查看錶 MyClass 中前2行數據
mysql> select * from MyClass order by id limit 0,2;
6、刪除表中數據
命令:delete from 表名 where 表達式
例如:刪除表 MyClass中編號為1 的記錄
mysql> delete from MyClass where id=1;
7、修改表中數據:update 表名 set 欄位=新值,… where 條件
mysql> update MyClass set name=''Mary'' where id=1;
8、在表中增加欄位:
命令:alter table 表名 add 欄位 類型 其他;
例如:在表MyClass中添加了一個欄位passtest,類型為int(4),默認值為0
mysql> alter table MyClass add passtest int(4) default ''0''
9、更改表名:
命令:rename table 原表名 to 新表名;
例如:在表MyClass名字更改為YouClass
mysql> rename table MyClass to YouClass;
更新欄位內容
update 表名 set 欄位名 = 新內容
update 表名 set 欄位名 = replace(欄位名,''舊內容'',''新內容'');

㈣ 關於資料庫操作

把兩個語句都列印出來,看一眼有什麼差異就知道問題所在了啊。我估計是日期格式的問題吧。
theday是一個字元串,在SQL語句中,如果欄位是時間類型,那麼你可能要把theday這個字元串用資料庫函數轉換成日期類型。

㈤ 資料庫基本操作是什麼

關系資料庫上的基本操作有選擇、投影、連接和除法,選擇建立一個含有與原始關系相同列數的新表,但是行只包括那些滿足某些特寫標準的原始關系行。投影操作指定將被選擇的列,因而形成的表只含有原始表列的一個子集。如果在投影操作刪除的列中有兩個行不同,那麼將只有一個記錄被轉入新的關系。連接操作從兩個或多個表中組合信息。兩個表中的公用欄位用作組合記錄的基礎欄位。在公用欄位中具有相等值的記錄被連接在結果關系內。

㈥ 資料庫的基本操作包括什麼

最基本的就是:增、刪、改、查
insert delete update select

㈦ SQL資料庫怎麼操作

資料庫連接:要有代碼在ASP.net中 可以用三層架構 也可以直接寫。這里給你例舉一段吧!1 )對表A 中的 1欄位添加內容://定義一個插入的方法用於將你要插入的值傳過來public string InsertTable(string a,string b,string c){string write=null;//定義一個返回值,賦值為空//定義資料庫連接欄位:這個欄位你可以通過一個DataGirdView空間連接資料庫找到 string str="Data Source=.;Initial Catalog=你的資料庫名字;Persist Security Info=True;User ID=用戶名;Password=你連接資料庫的密碼";//建立連接:
SqlConnection conn = new SqlConnection(str);//打開連接:
conn.Open();//執行SQL語句操作:例如對表A 中的 1欄位添加內容
string sql="insert into A values('"+a+"','"+b+"','"+c+"')"; //剛才所設置的變數就插入了,實際上你對表A進行了1.,2,3的插入。這個如果你在ASP.net中有textbox的話你就把三個變數設置為空從前面傳過來就可以了。//執行SQL語句:
SqlCommand com = new SqlCommand(sql, conn);
//語句是否插入:這里設置的變數i的目的就是看在資料庫中我們執行完insert不是都會產生「1行受影響」字樣嗎?那這里的i就是看你所插入的語句是否一行受影響。 int i=com.Executescale(); if(i>0) { write="sucess";//如果i>0,表示一行受影響,輸出成功 }else write="fail";//否則失敗return write;//返回一個輸出的值}2 ) 對表A 中的 1欄位查詢內容:pubic string SelectTable(string a){ string write=null; string str="Data Source=.;Initial Catalog=你的資料庫名字;Persist Security Info=True;User ID=用戶名;Password=你連接資料庫的密碼"; SqlConnection conn = new SqlConnection(str); conn.Open(); string sql="select * from A where 1='"+a+"'"; SqlCommand com = new SqlCommand(sql, conn);
SqlDataReader read = com.ExecuteReader(); if(read.Read())//若讀到了 { write="have"; }else write="no have";retrun write;}後面的也一樣 也可以用T-SQL和存儲過程寫 但是建議你是用這種方法 比較簡單。

㈧ 如何對資料庫進行操作

//此類為連接資料庫並進行資料庫的操作
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Conn {
private static Connection conn = null;
private static Statement st = null;
private static ResultSet rs = null;
//建立資料庫的連接
public Conn(){
String url = "jdbc:sqlserver://localhost:1433;databaseName=ZYGX";
String user = "sa";
String password = "123";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url, user, password);
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}

// 通過不同 的sql語句,得到相應Resultset結果集
public ResultSet getRs(String sql){
try{
rs= st.executeQuery(sql);
}catch(SQLException e){
e.printStackTrace();
}
return rs;
}
// 根據不同的sql語句,執行資料庫的更新操作
public int updata(String sql){
int num=0;
try{
num = st.executeUpdate(sql);
}catch(SQLException e){
e.printStackTrace();
}
return num;
}
// 關閉資料庫連接相應的資源
public void close(){
try{
if(rs!=null){
rs.close();
rs = null;
}
if(st!=null){
st.close();
st = null;
}
if(conn!=null){
conn.close();
conn = null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
----------------------------------------------------------------------
//可以對button里添加動作按鈕:
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
Conn conn =new Conn();
String sql1="select * from aa where name='" name "' ";//按name值查找
ResultSet rs = conn.getRs(sql1);
try {
while(rs.next()){
int n=rs.getString("type");
}
} catch (SQLException e) {
e.printStackTrace();
}
String name=textField.getText();
String sql="update aa set tittle='" name "' ";//從aa表將title欄位的值改成textField里的name值
String sql2 ="delete from aa where name='" name "'";//從aa表將按取得name的值刪除該行數據
String sql3 = "insert into aa (name,uname) values ('" name "','"')"; //將name,uname值新增到aa表
if(conn.update(sql)==1){
System.out.print("修改成功");
}
if(conn.update(sql2)==1){
System.out.print("刪除成功");
}
if(conn.update(sql3)==1){
System.out.print("新增成功");
}
}
});

㈨ 資料庫查詢操作

查詢語句中添加相關關鍵鍵值

㈩ 什麼是寫資料庫操作

LZ問題不太具體。
從字面上理解,就是你在程序前段所收集到的數據經過加工寫入資料庫的操作。
能夠修改資料庫的操作包括
insert into 語句——插入值
update ——修改值
delete ——刪除值

熱點內容
SQL寫序列 發布:2024-09-20 06:02:29 瀏覽:964
裝緩存下載 發布:2024-09-20 05:42:36 瀏覽:72
gon引擎自動回收腳本 發布:2024-09-20 05:39:39 瀏覽:246
好醫生連鎖店密碼多少 發布:2024-09-20 05:09:38 瀏覽:15
魔獸腳本代理 發布:2024-09-20 05:09:35 瀏覽:99
python登陸網頁 發布:2024-09-20 05:08:39 瀏覽:758
安卓qq飛車如何轉蘋果 發布:2024-09-20 04:54:30 瀏覽:178
存儲過程中in什麼意思 發布:2024-09-20 04:24:20 瀏覽:315
php顯示數據 發布:2024-09-20 03:48:38 瀏覽:501
源碼安裝軟體 發布:2024-09-20 03:44:31 瀏覽:354