简单的创建数据库的 SQL 语句: use master go if exists(select * from sysdatabases where name='Test') begin select '该数据库已存在' drop database Test --如果该数据库已经存在,那么就删除它 end else begin create database Test on primary --表示属于 primary 文件组 ( name='stuDB_data', -- 主数据文件的逻辑名称
有外键的主键设置自增. ; ALTER TABLE `<table>` MODIFY COLUMN `id` ) NOT NULL AUTO_INCREMENT FIRST; 创建数据库,创建新用户,超级用户给新用户赋权 create database dbName; create user userName@'%' identified by 'userPassword'; #创建新用户 grant all privileges on dbName.* to userName@'%'; #
查询表的所有列及其属性:select t.*,c.COMMENTS from user_tab_columns t,user_col_comments c where t.table_name = c.table_name and t.column_name = c.column_name and t.table_name = women;查找表的主键:select cu.* from user_cons_columns cu, user_constraints au where cu.cons
字段的修改.添加和删除 create table tf1( id int primary key auto_increment, x int, y int ); #修改 alter table tf1 modify x char(4) default''; alter table tf1 change y m char(4) default ''; #增加 alter table 表名 add 字段名 类型[(长度) 约束]; >:alter table student add name cha
今天上午刚刚弄明白了在navicat for mysql上如何设置外键,现在分享出来,希望能够对大家有帮助. 先介绍一下基本情况.现在有两个表一张是teacher表一张是dept表,现在我想把teacher表中的dept属性设置为外键,关联dept表中的code属性.具体情况如图:好了,基本情况介绍完毕,现在开始教你们navicat for mysql 怎么设置外键. 打开我的navicat,然后找到我的teacher表,选中它,然后点击菜单栏上的‘design table’. 2 在弹出的对话