如何在mysql中自动增加查找和插入数据

时间:2016-11-07 11:23:55

标签: mysql sql

# employee_code, name
TJU_741,        Sanjjev Kumar
TJU_856,        Akshay Mehta
GUEST_1,        ajay@gmail.com
GUEST_2,        x@yahoo.com

这是我的员工表我必须以这种方式插入数据像GUEST_2现在,如果我们插入另一个值,那么employee_code应该插入GUEST_3 ... 请告诉我如何找到GUEST_2,我们可以添加1我不插入mannualy它应该自动递增

 insert into employee (employee_code,name) values ('GUEST_3','xyz')

我执行此查询请建议我

1 个答案:

答案 0 :(得分:1)

按照步骤

第1步:创建表格

namespace HookingStudy
{
    class HookingClass          
    {
        private const int WM_KEYDOWN = 0x0100;
        private static LowLevelKeyboardProc _proc = hookCallBack;
        private static IntPtr _hookID = IntPtr.Zero;                    
        public static void Main()
        {
            Beep(1111, 222);
            _hookID = SetHook(_proc);
            Application.Run();
        }
        private static IntPtr hookCallBack(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if( nCode >= 0 && wParam == (IntPtr) WM_KEYDOWN )
            {
                int vkCode = Marshal.ReadInt32(lParam);
                if( vkCode.ToString() == "88" )                 //   88 ("x" key)
                {
                    Beep(7777, 222);
                    UnhookWindowsHookEx(_hookID);     
                    Process.GetCurrentProcess().Kill(); 
                }
                Beep(2222, 55);
            }
            return CallNextHookEx(_hookID, nCode, wParam, lParam);  
        }
        private static IntPtr SetHook(LowLevelKeyboardProc proc)
        {
            using( Process curProcess = Process.GetCurrentProcess() )
            using( ProcessModule curModule = curProcess.MainModule )
            {
                return SetWindowsHookEx(13, proc, GetModuleHandle(curModule.ModuleName), 0);
            }                   
        }
        private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
        [DllImport("KERNEL32.DLL")]                             
        extern public static void Beep(int freq, int dur);      
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool UnhookWindowsHookEx(IntPtr hhk);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr GetModuleHandle(string lpModuleName);
    }  
}

第2步:插入记录

create table employee (
emp_id int not null auto_increment primary key,
employee_code varchar(50) not null,
name varchar(50) not null
);

第3步:使用Concat()方法

insert into employee (employee_code,name) values ('GUEST','ABC');
insert into employee (employee_code,name) values ('GUEST','AAA');
insert into employee (employee_code,name) values ('GUEST','BBB');
insert into employee (employee_code,name) values ('GUEST','CCC');
insert into employee (employee_code,name) values ('GUEST','DDD');

第4步:您的输出:

enter image description here

我希望你在这里找到合适的解决方案..